Reputation: 1853
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?
Upvotes: 68
Views: 49381
Reputation: 11800
This solution toggles the search:
nnoremap <silent><expr> <c-l> (&hls && v:hlsearch ? ':nohls' : ':set hls')."\n" <BAR> redraw<CR>
Upvotes: 0
Reputation: 2628
This might suit your needs:
nnoremap <esc> :noh<return><esc>
With a little tinkering you can make it work in insert mode.
Upvotes: 6
Reputation: 15520
I have the following in my .vimrc
:
map <silent> <C-N> :let @/=""<CR>
Upvotes: 10
Reputation: 186562
:noremap <silent> <c-l> :nohls<cr><c-l>
This would redraw the screen and clear any search terms with Control-L, handy :) easier than reaching up to the F keys.
Upvotes: 17
Reputation: 99264
I use
/pleasedisablehighlightthanks
command. Or just
/qewrufhiqwe
But you should be carefult not to mix this with the following command!
/qewrufhiqew
Upvotes: 47
Reputation: 311526
Try this:
set hlsearch!
nnoremap <F12> :set hlsearch!<CR>
and hit F12 to clear when desired. Use :noh
in command mode to clear.
Upvotes: 5
Reputation: 14185
you could search for something not in the text file. Nothing will be highlighted in this case. (e.g. /349i5u9sgh)
Upvotes: 1