Reputation: 133
I am checking a log file using vim. There's only one word can be highlighted, when I search another word,the second word is highlighted but the previous one is not highlighted anymore.
Can anyone show me a way that easily highlight/cancel highlight multiple words in vim? For example, I want to highlight words "stack", "over" and "flow", then I want to cancel the highlight of "stack" and highlight another word "error". So that I can analyze the log more efficiently. Thanks.
Upvotes: 13
Views: 17971
Reputation: 2022
There are two simple ways to highlight multiple words in vim editor.
Basically the first way puts you in the regular expression mode so that you do not need to put any extra back slashes before every pipe or other delimiters used for searching.
Upvotes: 29
Reputation: 172590
To have all words highlighted in the same color and be able to search and replace all of then, add them as alternatives to the search pattern, e.g. /foo\|bar
. My SearchAlternatives plugin provides handy mappings to add and remove patterns.
If you want different colors for different matches, you need a highlight mechanism different from the built-in search. My Mark plugin is used by many people for that. (The plugin page has links to alternative plugins.)
Upvotes: 3
Reputation: 8548
/\v\/folder|\/copy
- search for \folder
and \copy
and add to .vimrc
set hlsearch
Upvotes: 14