vimtricks.wiki Concise Vim tricks, one at a time.

How do I clear search highlighting in Vim?

Answer

:noh

Explanation

The :noh (short for :nohlsearch) command clears the highlighting from the last search pattern. When you search with /pattern or *, Vim highlights all matches in the file. These highlights persist until you run :noh or search for something else.

How it works

  • :noh turns off the current search highlighting
  • It does not disable the hlsearch option — the next time you search, highlights will appear again
  • It only affects the display, not the search register — you can still press n to jump to the next match

Example

You search for /error and every occurrence of "error" in the file is highlighted in yellow. After reviewing the results, the highlights are distracting. Type :noh<CR> and all the highlights disappear.

The next time you press n or /, highlighting will come back for the new or continued search.

Tips

  • Many users map this to a key for quick access. A popular mapping:
nnoremap <Esc><Esc> :nohlsearch<CR>
  • Another common mapping uses <leader>:
nnoremap <leader><space> :nohlsearch<CR>
  • Use :set nohlsearch to disable search highlighting permanently (not recommended — you lose a useful visual cue)
  • Use :set hlsearch to re-enable it if you turned it off
  • The full command is :nohlsearch but :noh is the shortest unambiguous abbreviation

Next

How do I edit multiple lines at once using multiple cursors in Vim?