I want vim to start highlighting matches right away as I type after typing '/'. But that highlight color should be different from the color of the existing matches.
Example, I have the following text:
foo bar baz
After the end of this sequence:
/foo<return>/bar
(Note that this sequence was typed in normal mode and no <return>
was pressed at the end of the sequence)
foo should be highlighted with one color (call it "found match" color) and bar should be highlighted with another color (the incremental search color).
You cannot do this with the built-in search. Vim will always highlight the next match with IncSearch
, and all other matches (of the same, currently typed pattern) with the Search
highlight group (assuming you have :set hlsearch incsearch
).
If you want to keep the previous match, you have to define your own highlighting, e.g. like this (in the current window only):
:hi def link PreviousSearch MoreMsg " Define some different highlight group based on some existing one.
:execute 'match PreviousSearch /' . @/ . '/'
If you need more than one concurrent match, and a more robust implementation that covers all windows and tabs (and a lot of extra features), have a look at my Mark plugin. (The plugin page has links to alternative plugins.)