Roger
Roger

Reputation: 1853

How to get rid of search highlight in Vim

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

Answers (8)

SergioAraujo
SergioAraujo

Reputation: 11800

This solution toggles the search:

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

Upvotes: 0

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143081

Try the :noh command.

vi/vim notes

Upvotes: 116

Mosh
Mosh

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

jqno
jqno

Reputation: 15520

I have the following in my .vimrc:

map <silent> <C-N> :let @/=""<CR>

Upvotes: 10

meder omuraliev
meder omuraliev

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

P Shved
P Shved

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

John Feminella
John Feminella

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

Ben Hughes
Ben Hughes

Reputation: 14185

you could search for something not in the text file. Nothing will be highlighted in this case. (e.g. /349i5u9sgh)

Upvotes: 1

Related Questions