Highlight all occurrence of a selected word?

Matteo Cocon picture Matteo Cocon · Aug 7, 2010 · Viewed 143.5k times · Source

How can I highlight all occurrence of a selected word in GVim, like in Notepad++?

Answer

wilhelmtell picture wilhelmtell · Aug 7, 2010

In Normal mode:

:set hlsearch

Then search for a pattern with the command / in Normal mode, or <Ctrl>o followed by / in Insert mode. * in Normal mode will search for the next occurrence of the word under the cursor. The hlsearch option will highlight all of them if set. # will search for the previous occurrence of the word.

To remove the highlight of the previous search:

:nohlsearch

You might wish to map :nohlsearch<CR> to some convenient key.