1

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?

2

1 Answer 1

8

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.