Wiki

by yszheda

View project onGitHub

Tip 80: Highlight Search Matches

Return to the top: <<Practical Vim>>

  • highlighting search matches: enabling the 'hlsearch' option.

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h 'hlsearch'

Mute Search Highlighting

  • disable the search highlighting feature entirely:
    • :set nohlsearch
    • :se nohls
    • :se hls!
  • mute the search highlighting temporarily: :nohlsearch

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h :noh

Create a Shortcut to Mute Highlighting

nnoremap <silent> <C-l> :<C-u>nohlsearch<CR><C-l>

Normally, <C-l> clears and redraws the screen:

References:

# If you open the file in vim,
# then you can \"ayy@a the next line to execute the vim command: 
:h CTRL-L