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
- Place cursor on the word to replace
*searches for the word (highlights all occurrences)ciw+ type replacement +<Esc>nmoves to the next occurrence.repeats the replacement
Example
To rename count to total selectively:
- Cursor on
count, press* - Press
ciwtotal<Esc> - Press
nto find next,.to replace (ornto skip)
Tips
- This is often called the "dot formula"
- More flexible than
:%sbecause you can skip occurrences nfinds the next,.applies the change- Works for any word or text object change
- Combine with
Nto go backward