How to get rid of search highlight in Vim
VimVim Problem Overview
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?
Vim Solutions
Solution 1 - Vim
Try the :noh
command.
Solution 2 - Vim
I use
/pleasedisablehighlightthanks
command. Or just
/qewrufhiqwe
But you should be carefult not to mix this with the following command!
/qewrufhiqew
Solution 3 - Vim
: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.
Solution 4 - Vim
I have the following in my .vimrc
:
map <silent> <C-N> :let @/=""<CR>
Solution 5 - Vim
Try this:
set hlsearch!
nnoremap <F12> :set hlsearch!<CR>
and hit F12 to clear when desired. Use :noh
in command mode to clear.
Solution 6 - Vim
This might suit your needs:
nnoremap <esc> :noh<return><esc>
With a little tinkering you can make it work in insert mode.
Solution 7 - Vim
you could search for something not in the text file. Nothing will be highlighted in this case. (e.g. /349i5u9sgh)
Solution 8 - Vim
This solution toggles the search:
nnoremap <silent><expr> <c-l> (&hls && v:hlsearch ? ':nohls' : ':set hls')."\n" <BAR> redraw<CR>