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?
MultipleSearch2 is another script which is integrated with vim's search: http://www.vim.org/scripts/script.php?script_id=1183
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)
:%s /red\|green\|blue/
I am not sure about how to keep different colors for different keyword though. Thanks.
Try "Highlight multiple words", which uses matchadd()
.