Step 3 of 7

Macros take counts

Macros take counts

Just like motions, q accepts a count. 3q replays the macro three times back to back, 10q ten times, and so on.

That’s only useful if each replay ends up somewhere new, so the trick is to record the move to the next line as part of the macro. A macro that edits the line and then presses j will march down the buffer one line per replay, and the count decides how far it marches.

Try it in the editor. Work through the checklist below. Record a macro that puts - in front of the line and then moves down with j. Stop recording, and press 3q to finish the other three lines.

  1. Start recording Start recording.
  2. Turn the first line into a list item Insert - (a dash and a space) at the start of the line, inside the recording.
  3. Move down a line, still recording Down one line — this keystroke becomes part of the macro.
  4. Stop recording Stop recording.
  5. Replay it three times A counted replay — the remaining three lines get their dashes in one go.
Start recording Start recording.

Next: Turn the first line into a list item

Loading editor…