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?
If I type
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.
One option is that you can have a confirmation flag
[c] Confirm each substitution. Vim highlights the matching string. You can type: 'y' to substitute this match 'l' to substitute this match and then quit ("last") 'n' to skip this match <Esc> to quit substituting 'a' to substitute this and all remaining matches 'q' to quit substituting
You can also try
grep command to see the filtered output and the highlighted original file.