How to get rid of search highlight in Vim

Viewed 45171

I have :set hlsearch as default value.

When I search for something, search terms get highlighted. However many times I want to get rid of the highlight, so I do :set nohlsearch. In this way I get rid of highlights for the time being.

However if I do a new search, then search terms are not highlighted.

I would like to hit ESC + ESC to get rid of highlights and then set back :set hlsearch.

Any suggestions?

8 Answers

This solution toggles the search:

nnoremap <silent><expr> <c-l> (&hls && v:hlsearch ? ':nohls' : ':set hls')."\n" <BAR> redraw<CR>
Related