DEV Community

Serhat Teker
Serhat Teker

Posted on • Originally published at tech.serhatteker.com on

Clear Search Highlight in Vim

After searching in Vim with / all occurences highlighted and this stays for a while. It may be a unwanted or even annoying thing. There are many methods to disable it;

0: Temporarily Disable

To turn off highlight until next search, in exe mode:

:noh
Enter fullscreen mode Exit fullscreen mode

1: Persistent Disable

If you want to disable it completely:

1.0: For existing session/buffer:

In exe mode:

:set nohlsearch
Enter fullscreen mode Exit fullscreen mode

1.1: For all sessions/buffers:

Put this in your .vimrc:

" disable search highlight
set nohlsearch
Enter fullscreen mode Exit fullscreen mode

P.S:

I personally use 'temporarily disable' with key mapping. I mapped :noh to <esc> key. Since hitting <esc> is a very common and intuitive situtation in Vim.

" noh - no highlight
map <esc> :noh <CR>
Enter fullscreen mode Exit fullscreen mode

You can also map nohlsearch to a key for toggling.

All done!

Top comments (0)