*, cw, then . . . โ The Replace Loop
Search a word, change one, repeat with dot.
*cwNEW Esc, then n.n.n. โ change every occurrence of a word, one at a time, with confirmation. The most-loved Vim refactoring loop.
*, cw, then . . . โ The Replace Loop
The classic Vim refactoring loop. Searches for a word, changes one instance, then jumps to each next match where you decide whether to dot-repeat (apply) or skip.
| Key | Note |
|---|---|
| * | Cursor on word: search next exact match |
| cw | Change word โ Vim drops you in Insert |
| NEW | Type replacement |
| Esc | Back to Normal โ change is saved as the dot-target |
| n | Jump to next match |
| . | Apply the same change |
| n | Skip this one โ just move to next |
| . | Applyโฆ |
Worked example โ * cw . . .
Search-cursor-change-repeat โ mass rename.
The classic Vim mass-edit. cgn is similar and even slicker โ see cgn-dot.
Watch
- ๐บ #0463 ddp โ Swap Lines Down (not yet published)
- ๐บ #0464 ddP โ Swap Lines Up (not yet published)
See also: Word Search, Repeat Last Change, {key:cgn} โ Change-Next-Match Loop