2

I want to write some mappings so I can move faster between the code. The problem is that I have hlsearch on(and i don't want it off) so I did it like this:

au BufNewFile,BufRead *.py
    nnoremap <Leader>r /return<CR>:noh<CR>
    nnoremap <Leader>nf /def .*(.*):<CR>:noh<CR>
    nnoremap <Leader>pf ?def .*(.*):<CR>:noh<CR>
    nnoremap <Leader>nc /class<CR>:noh<CR>
    nnoremap <Leader>pc ?class<CR>:noh<CR>

I added :noh<CR> to disable highlighting after search, but that makes "flickering" effect which is unpleasing.

Is there a way to disable highlighting just for the next search or other solution?

3

You can perform a search without setting any highlight with the :h search() function.

For example, this will jump to the next occurrence of a 'return' preceded by optional space characters only:

nnoremap <leader>r :call search("\s*return")<cr>
0

I really like vim-cool for this. It doesn't exactly achieve what you want, because it (instead) automatically runs :nohlsearch when the cursor moves, or various other things. I've found it far more intuitive than dealing with various possible manual ways.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.