level 10

Macros

Record a sequence of edits and replay it across lines.

The dot command repeats your last change. A macro repeats your last routine — a whole sequence of moves and edits, replayed on command. This is the answer to the task that would otherwise eat your afternoon: “make this same fiddly edit in fifty places.” Record it once, fire it fifty times, go get coffee.

Recording and Replaying

q{letter}  → start recording into a register (qa)
q          → stop recording
@{letter}  → replay the macro (@a)
@@         → repeat the last macro
5@a        → replay 5 times

Tips

  • Start from a known position — macros replay exactly what you recorded, so keep them positionally consistent.
  • End with a motion to the next target (often j) so each replay lands ready for the next.
  • Use n inside a macro to jump by search when targets aren’t evenly spaced.

Use the dot command for a single repeated change; reach for a macro when you need to chain several commands together.

Your first macro — add semicolons

  1. On line 1, press qa to start recording into register a.
  2. Press A, type ;, press Esc.
  3. Press j to move down, then q to stop recording.
  4. Press 7@a to apply it to the remaining lines.
normalpress i to type · hjkl to move

goal Record A; Esc j once, then replay it down the block.

Wrap each value in quotes

  1. On red, press qa.
  2. Press I, type ", press Esc.
  3. Press A, type ",, press Esc.
  4. Press j, then q to stop.
  5. Press 5@a for the remaining lines.
normalpress i to type · hjkl to move

goal A macro can mix line-start and line-end edits.

Prefix each line

  1. On line 1, press qa.
  2. Press I, type async , press Esc.
  3. Press j, then q.
  4. Press 4@a to apply to the rest.
normalpress i to type · hjkl to move

goal Insert at the line start, then move on.

Step through with @@

  1. On line 1, record qa: press I, type - [ ] , press Esc, press j, press q.
  2. Press @a on line 2.
  3. Press @@ to repeat on line 3.
  4. Press @@ again for lines 4 and 5 — inspecting each result as you go.
normalpress i to type · hjkl to move

goal Replay once with @a, then @@ to repeat one item at a time.

Capstone — a macro that searches and edits

The lines start differently, so columns won’t help and the targets aren’t adjacent — this is the job the dot command can’t finish on its own. Each getValue("...") needs to become a bare fetch(): rename the call and empty the arguments. Bake the search into the macro so every replay finds its own next target.

  1. Press gg to start from a known spot.
  2. Record: qa, then /getValue and Enter to land on the first call.
  3. Press ciw, type fetch, press Esc — the name is changed.
  4. Press f(, then ci( and Esc — the argument is gone, leaving fetch().
  5. Press q to stop.
  6. Press 3@a — the search makes each replay hunt down the next call by itself.
normalpress i to type · hjkl to move

goal When targets aren't aligned, search inside the macro and do two edits per hit.