Learn Vim / Multiply the macro — vim

Multiply the macro — vim

The answerCanonical keystrokes: qa r* j q 5@a.

Try it on a real buffer

Six lines, same fix: turn each “- ” into “* ”. Record the fix for line 1 with qa (change the dash, step down), q to stop, then replay it five times at once with 5@a.

- one
- two
- three
- four
- five
- six

Canonical solution: qa r* j q 5@a · target: 9 keystrokes — the fewest that solve it (every keypress counts).

Why it works

A count in front of a macro runs it that many times: 5@a is @a @a @a @a @a. Record a clean one-line fix that ends by moving to the next line, and a single count finishes the whole list.

▶ live vim buffertarget 9 keystrokes
Six lines, same fix: turn each “- ” into “* ”. Record the fix for line 1 with qa (change the dash, step down), q to stop, then replay it five times at once with 5@a.

Reading about keystrokes doesn't build keystrokes. Try this in a real vim buffer right now — the “Multiply the macro” mission takes about a minute.

Sign in free to practice →

Keep going