Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim clear last search highlighting

After doing a search in Vim, I get all the occurrences highlighted. How can I disable that? I now do another search for something gibberish that can't be found.

Is there a way to just temporarily disable the highlight and then re-enable it when needed again?

like image 688
Gabriel Solomon Avatar asked Mar 18 '09 09:03

Gabriel Solomon


People also ask

What is Hlsearch in Vim?

Highlighting search matches To highlight all search matches, set the following option: :set hlsearch. With the defaults, setting this option causes all text matching the current search to be highlighted using the Search highlight group, which adds a yellow background to the current highlighting.

How do I change the highlight color in VIM?

You can change color schemes at anytime in vi by typing colorscheme followed by a space and the name of the color scheme. For more color schemes, you can browse this library on the vim website. You can enable or disable colors by simply typing "syntax on" or "syntax off" in vi.


2 Answers

To turn off highlighting until the next search:

:noh 

Or turn off highlighting completely:

set nohlsearch 

Or, to toggle it:

set hlsearch!  nnoremap <F3> :set hlsearch!<CR> 
like image 119
Mykola Golubyev Avatar answered Oct 20 '22 12:10

Mykola Golubyev


From the VIM Documentation

To clear the last used search pattern:

:let @/ = "" 

This will not set the pattern to an empty string, because that would match everywhere. The pattern is really cleared, like when starting Vim.

like image 41
Shaun Bouckaert Avatar answered Oct 20 '22 11:10

Shaun Bouckaert