Vim clear last search highlighting

ID : 397

viewed : 274

Tags : vimfull-text-searchhighlightvim

Top 5 Answer for Vim clear last search highlighting

vote vote


To turn off highlighting until the next search:


Or turn off highlighting completely:

set nohlsearch 

Or, to toggle it:

set hlsearch!  nnoremap <F3> :set hlsearch!<CR> 
vote vote


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.

vote vote


You can do


or :nohlsearch to temporarily disable search highlighting until the next search.

vote vote


I found this answer years ago on

Add the following to your .vimrc:

"This unsets the "last search pattern" register by hitting return nnoremap <CR> :noh<CR><CR> 

Thus, after your search, just hit return again in command mode, and the highlighting disappears.

vote vote



" Clear highlighting on escape in normal mode nnoremap <esc> :noh<return><esc> nnoremap <esc>^[ <esc>^[ 

The second line is needed for mapping to the escape key since Vim internally uses escape to represent special keys.

Top 3 video Explaining Vim clear last search highlighting