1

This question already has an answer here:

I'd like to pass through a text an replace word1 by word2. However, I don't want to execute this task in one pass, but rather word by word. I know I could put the cursor on the word I want, execute *, then vw and finally r words. The problem is located on this last step. If I want to look for the next words, I can't with *, because I'd replace word1 by word2. Could anyone be able to help me at this point?

marked as duplicate by Martin Tournoij Feb 23 '17 at 17:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

7

I think you're looking for the substitute command with confirmation:

:%s/word1/word2/gc

This will substitute word2 for word1, but every time it will take you to the match and let you decide what to do.

  • g means global. It will find all matches on the line.
  • c is for confirm. It applies the behavior described above.

See :help :substitute and :help :s_c for more info.