Alex Rivera | Logout

Is there any way to highlight multiple searches in (g)Vim?

Asked 2009-04-01T07:40:10.617
120

I want to search for multiple strings in Vim/gVim and have them highlighted in different colours. Is there a way of doing this with out-the-box Vim or with a plug-in?

Edit
Report

2 Answers

9

Yes, out-of-the-box you can use matchadd().

To add a highlight, eg. for trailing whitespace:

:highlight ExtraWhitespace ctermbg=grey guibg=grey
:call matchadd('ExtraWhitespace', '\s\+$', 11)

To view all matches:

:echo getmatches()

To remove matches use matchdelete(). Eg.:

:call matchdelete(7)
answered 2012-12-15T04:23:56.810
5

MultipleSearch : Highlight multiple searches at the same time, each with a different color.

http://www.vim.org/scripts/script.php?script_id=479

:Search <pattern1> //will highlight all occurences of <pattern1> in the current buffer.
A subsequent :Search <pattern2> will highlight all occurences of <pattern2> in the current buffer.
answered 2009-07-01T19:32:33.133

Your Answer