VIM see regular expressions matches as you type

regular expressionvim

If I type /regex then the cursor temporarily jumps to the first match and all matches are highlighted. This updates as I type. Is it possible to get this behavior when I'm getting ready to make a substitution? For instance, when I'm working on a complicated regular expression :%s/\<regex\>/, I would like to know what is matching before I pull the trigger and change everything. Any way to do it?

Best Answer

Type your search using / (or ?) to begin with, which will allow you to tweak your regex (since you're using incsearch)

Once you get it all nice, you can use the previous search pattern (the one you just used) in the substitute command by using two separators for the 'search' item:

/elephant                       " find the next elephant
:%s//rhino/gc                   " make then all rhinos!

Of course, you can use selections and ranges, as normal.

:1,15s,,cougar,g
:'<,'>s::tiger:
Related Question