Reputation: 6619
I used to use some interactive search and replace in Vi but I totally forgot about it. Let's explain what I remember because I am currently confused when tried to find out the official ways to replace:
It was close to search by :/pattern but something more like :/pattern/replacement and then I could approve one by one every found string and jump to next occurence by pressing 'n' or selectively replace with the replacement pressing 'r'.
Did I dream that? All I see are regex to do replacements at once and alternatively asking you for a confirmation!
Upvotes: 0
Views: 701
Reputation: 3698
A solution without regex:
Search the word you want to replace with:
/foo
or ?foo
for backward search.
Type cw
to change the word to a new one.
Press n
to get to the next occurrence of this word and now either:
.
to replace the word or n
for next occurrence.
Upvotes: 1
Reputation: 37906
Add c
to the flags.
For example
:%s/pattern/replacement/c
Searches globally for pattern
and asks you whether to replace it with replacement
See the vim documentation for more information about these flags.
Upvotes: 2