Step 3 of 6

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 Press Q.
  2. Turn the first line into a list item Press I, type - (a dash and a space), and press Esc.
  3. Move down a line, still recording Press j — this keystroke becomes part of the macro.
  4. Stop recording Press Q.
  5. Replay it three times Press 3q — the remaining three lines get their dashes in one go.
Start recording Press Q.

Next: Turn the first line into a list item

Loading editor…