Macros in Vim

From the Vim cheat sheet · Macros & Registers · verified Jul 2026

Macros

Recording and executing repetitive tasks

text
qa - Start recording macro in register a
q - Stop recording
@a - Execute macro from register a
@@ - Execute last macro again
5@a - Execute macro a 5 times

# Example: Add semicolon to end of lines
qa - Start recording to register a
$ - Go to end of line
a; - Append semicolon
<Esc> - Back to normal mode
j - Move to next line
q - Stop recording
@a - Execute on next line
10@a - Execute on next 10 lines
💡 Use any letter a-z as macro register
⚡ @@ repeats the last executed macro
📌 Record once, replay many times
🟢 Start simple: record, test, then bulk apply
macrosautomation

More Vim tasks

Back to the full Vim cheat sheet