vimmacvim

How to highlight all occurrences of a selected word in VIM?


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


Solution

  • 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.