History Report a problem
Article Edit this page Discussion

Highlight all search pattern matches

From Vim Tips Wiki

(Redirected from VimTip14)
Jump to: navigation, search

Tip 14 Previous TipNext Tip

Created: February 24, 2001 Complexity: basic Author: Yegappan Minimum version: 5.7 Karma: 562/234 Imported from: Tip#14


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 in yellow.

To disable the highlighting temporarily, enter (this is a command, not an option):

:nohlsearch

This command removes the highlighting for the current search. The highlighting returns for the next search.

To disable highlighting completely, set the following option:

:set nohlsearch

[edit] Mappings

Here are some alternative mappings that you could use in your vimrc to simplify changing search highlights.

" Press Space to turn off highlighting and blank message.
:noremap <silent> <Space> :silent noh<bar>:echo ""<CR>

" Press Ctrl-N to turn off highlighting.
:noremap <silent> <C-N> :silent noh<CR>

" Toggle highlighting on/off.
:noremap <F4> :set hls!<CR>

[edit] References

[edit] Comments

With the following in vimrc, you can press Enter to clear search highlighting.

" Clear search highlight by hitting Enter.
" The <tt>/<BS></tt> is a trick to clear the command line.
" The final <CR> restores the standard behaviour so
" pressing Enter moves to the next line.
:nnoremap <CR> :nohlsearch<CR>/<BS><CR>

A hack to temporarily remove highlighting is to search for nonexistent text:

/xxxxx

You can use a less prominent highlight (for gvim):

:hi Search guibg=LightGreen
or
:hi Search guibg=LightBlue

Or you can use modify the colours for vim:

:hi Search ctermbg=LightGreen ctermfg=red term=bold cterm=bold

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Pushing Daisies
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Astronomy Wiki
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions


Vote for featured Wikia!

Send this article to a friend
"Highlight all search pattern matches"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation