For example I'm in python code and want to jump between classes:
nnoremap <buffer> [c /^\s*class\ <CR>
How to prevent them from highlight in more elegant way than :nohl
at the end of command each time?
You can avoid highlighting search matches by using the :help search()
function or writing your own function.
search()
nnoremap <buffer> <silent> [c :<C-u>call search('^\s*\zsclass\s')<CR>
" with ':help :normal'
function! JumpToNextClass()
normal! /^\s*\zsclass\s
endfunction
" with ':help search()'
function! JumpToNextClass()
call search('^\s*\zsclass\s')
endfunction
nnoremap <buffer> <silent> [c :<C-u>call JumpToNextClass()<CR>
But none of that really matters since Vim already comes with ]]
and [[
.