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

How do I highlight all search matches in the file?

Answer

:set hlsearch

Explanation

The hlsearch option highlights all matches of the current search pattern throughout the file, making it easy to see where matches occur.

How it works

  • :set hlsearch enables persistent highlighting of search matches
  • All matches are highlighted, not just the one under the cursor
  • Highlighting persists until you search for something new or run :nohlsearch

Example

With hlsearch enabled, searching /error highlights every occurrence of "error" in the file with a yellow (or theme-appropriate) background.

Tips

  • :nohlsearch (:noh) temporarily clears the highlighting
  • :set nohlsearch permanently disables it
  • Put set hlsearch in your vimrc for permanent activation
  • Combine with incsearch for the best search experience

Next

How do you yank a single word into a named register?