vimtricks.wiki Concise Vim tricks, one at a time.

How do I quickly replace a word and then repeat it elsewhere?

Answer

ciw + new text + Esc, then n.

Explanation

The ciw command followed by new text, combined with * and . creates a powerful manual search-and-replace workflow that gives you full control.

How it works

  1. Place cursor on the word to replace
  2. * searches for the word (highlights all occurrences)
  3. ciw + type replacement + <Esc>
  4. n moves to the next occurrence
  5. . repeats the replacement

Example

To rename count to total selectively:

  1. Cursor on count, press *
  2. Press ciwtotal<Esc>
  3. Press n to find next, . to replace (or n to skip)

Tips

  • This is often called the "dot formula"
  • More flexible than :%s because you can skip occurrences
  • n finds the next, . applies the change
  • Works for any word or text object change
  • Combine with N to go backward

Next

How do you yank a single word into a named register?