How do I quickly repeat the last macro I executed?
Answer
@@
Explanation
How it works
After running a macro with @a (or any other register), you can repeat that same macro by pressing @@. This is a convenient shortcut that saves you from remembering which register the macro was stored in.
Vim keeps track of the last macro you executed, so @@ simply replays it without requiring you to specify the register letter again. This is especially useful when you are applying the same macro to many lines or sections of text.
You can also combine @@ with a count. For example, 5@@ will run the last-executed macro five more times.
Example
Suppose you recorded a macro in register a that wraps a word in parentheses:
- Record:
qathenbi(thenEscthenea)thenEscthenq - Move to the next word and run
@ato apply it - Move to another word and simply press
@@to apply the same macro again - Keep pressing
@@for each additional word you want to wrap
This avoids the need to remember @a each time. The @@ shortcut works identically regardless of which register the original macro was stored in.