How do I combine the dot command with macros for powerful repeat workflows?
Answer
qq;.q then @q or @@
Explanation
The dot command (.) repeats the last change, and when combined with a motion in a macro, it creates a find-and-apply pattern. Record a macro that moves to the next target (;, n, }) and applies the last change (.), then repeat the macro to transform multiple locations.
How it works
- Make your first change manually (e.g.,
ciw new_name<Esc>) - Record a macro that: moves to the next target + applies
. - Replay the macro to apply the same change at each subsequent location
@@repeats the last played macro
Example
" Change first 'old' to 'new'
/old<CR>cwnew<Esc>
" Record: go to next match and repeat change
qqn.q
" Apply to remaining matches
@q@q@q (or 10@q for all)
Before:
old value, old data, old name
After:
new value, new data, new name
Tips
n.n.n.without a macro is the manual equivalent@@repeats the last macro — saves keystrokes after@q- The dot command remembers insert-mode text, so
ciwchanges are fully captured cgnis a modern alternative: search first, thencgnchanges the next match and.repeats