Matthias Bergert's answer does the trick if you just need to replace one word and the replacement text is always corrected. Perhaps this is satisfied with 70% of our daily editing. If you need power s/.../.../ for your replacement needs, this may not be enough. For example, substitution of several words, backward link or expressions of functions in the replacement part.
I might think first do a:
:s/substitute/sub/c
note without % range and g .
then you simply:
- press
n or n to search / reverse search, - if you think the match should be replaced, click
& , - If you make a mistake, press
u
Key, & will perform the last replacement.
This way you can perform more complex substitutions, which is difficult for a simple cw like:
s/f../&, / add a comma after all the words fxx (foo, far, fur ...)s/\v(foo)(\d+)/\=submatch(1).(submatch(2)+1)/ increment number after foo- etc.
source share