JohnBeckett (talk | contribs) (Use '^=' to prepend 'h' to viminfo to avoid conflict if 'n' option used) |
(Adjust previous/next navigation) |
||
Line 2: | Line 2: | ||
{{TipImported |
{{TipImported |
||
|id=14 |
|id=14 |
||
− | |previous= |
+ | |previous=12 |
|next=15 |
|next=15 |
||
|created=February 24, 2001 |
|created=February 24, 2001 |
Revision as of 03:03, 29 September 2008
created February 24, 2001 · complexity basic · author Yegappan · version 5.7
To highlight all search matches in a file, set the following option:
:set hlsearch
When this option is set, if you search for a pattern, all matches in the file will be highlighted using the Search highlight group, which defaults to adding a yellow background to the current highlighting. See :help hl-Search, or type :hi Search to see what color you have it set to. You can easily change the default highlighting with, for example, :hi Search guibg=LightBlue.
To disable the highlighting temporarily, enter (this is a command, not an option):
:nohlsearch
This command (which can be abbreviated to :noh) removes the highlighting for the current search. The highlighting returns for the next search.
If you do this often, put a mapping in your vimrc, like this:
" Press Space to turn off highlighting and clear any message already displayed. :noremap <silent> <Space> :silent noh<Bar>echo<CR>
To disable highlighting completely, even after a subsequent search, use:
:set nohlsearch
If you want to be able to enable/disable highlighting quickly, you can map a key to toggle the hlsearch option:
" Press F4 to toggle highlighting on/off. :noremap <F4> :set hls!<CR>
Highlighting can be enabled on Vim startup, when reading the viminfo file. Add the following to your vimrc if you want Vim to start with no search highlighting:
:set viminfo^=h
References
- :help 'hlsearch' Option to control search highlighting.
- :help :nohlsearch Command to temporarily remove search highlighting.
- :help :match You can highlight more than the search pattern.
- :help 'viminfo' Include h to disable the effect of 'hlsearch'.