Search code examples
vimhighlightwords

How to cancel vim highlight after I "gd" on a word?


I use "gd" on a word to highlight all its instance, fine. Then I wish these highlight should disappear because I don't want to be disturbed. Any vim command to dis-highlight last result?


Solution

  • You can use the function clearmatches or command noh to clear all highlights.

    :noh
    
    :call clearmatches()
    

    I've got it re-maped in my .vimrc

    noremap <leader>g :noh<cr>:call clearmatches()<cr>
    

    From :h noh

    Stop the highlighting for the 'hlsearch' option. It
    is automatically turned back on when using a search
    command, or setting the 'hlsearch' option.