How do I record one edit and replay it on the next two lines with a macro?
Answer
qqgUiwjq2@q
Explanation
Macros are strongest when the edit pattern is stable but too awkward for a one-liner substitute. qqgUiwjq2@q records a small transformation once, moves to the next line, then replays it with a count. This gives you fast batch editing without leaving Normal mode.
How it works
qqstarts recording into registerq.gUiwuppercases the inner word under the cursor.jmoves to the next line so the macro naturally advances.qstops recording.2@qreplays the macro two more times.
Because movement is baked into the macro, each replay lands on the next target line automatically. This is the key pattern for reliable macro design: perform the edit, then move to where the next edit should begin.
Example
Starting text:
alpha one
beta two
gamma three
Run:
qqgUiwjq2@q
Result:
ALPHA one
BETA two
GAMMA three
Tips
- Replace
2@qwith99@qwhen you want to run until an error stops replay. - Use
@@to repeat the last macro once more. - Keep macros deterministic: avoid jumps that depend on hidden folds or search state.