macro

q / @

q{register} starts recording a macro into that register; press q again to stop. Play it back with @{register}, and repeat the last macro with @@. Macros are just recorded keystrokes — anything you can do by hand, you can automate.

q{register} … q       @{register}  (normal mode)

Variations

Keystroke Effect
@@ Replay the last executed macro
10@a Run macro 'a' ten times
qA APPEND further keystrokes to existing macro in register a
:reg a Show the raw contents of register a (view/edit your macro)

Examples

qaIfoo <Esc>jq

Record macro 'a': insert 'foo ' at line start, go down

10@a

Apply macro 'a' to the next 10 lines

@@

Repeat the last macro one more time

Gotcha

If your macro navigates with j/l and hits a short line, it can fail silently or land in the wrong spot — write macros with 0/$/w for reliable anchoring.

Related

← All Vim commands · Vim cheat sheet