How do I replace the next word with a yanked word without clobbering the unnamed register?
Answer
yiww"_ciw\<C-r>0\<Esc>
Explanation
When you are doing repetitive refactors, cw is fast but it overwrites the unnamed register with the replaced text. This sequence avoids that by yanking once, moving to the next target, and changing through the black-hole register while pasting from register 0. It is a compact way to do repeatable replacements without losing your original yank.
How it works
yiwyanks the current word into register0wjumps to the next word"_ciwchanges that word using the black-hole register, so deleted text is discarded\<C-r>0inserts the contents of register0while in Insert mode\<Esc>returns to Normal mode
This is especially useful when propagating an identifier or token across nearby positions while keeping register state stable for subsequent edits.
Example
Before:
alpha beta
Run with cursor on alpha:
yiww"_ciw<C-r>0<Esc>
After:
alpha alpha
Tips
- Use
binstead ofwif your next target is backward. - Once the first replacement is done,
.can often repeat the change pattern efficiently.