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 hlsearchenables 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 nohlsearchpermanently disables it- Put
set hlsearchin your vimrc for permanent activation - Combine with
incsearchfor the best search experience