Replaying macros
Once you’ve recorded a macro, you can replay it by typing @, followed by the name of the macro in normal. For example — if you record a macro called a with qa, then you can replay that macro with @a in normal mode.
It’s easier to see the magic of macros in practice, so let’s try this in the editor. Here’s what you should do:
- Move your cursor to the first line in the editor
- Record a macro called
awithqain normal mode - Once you’re recording, prefix the line with a
X(hint:IX), and go back to normal mode - Add a
Xto the end of the line (hint:AX), and go back to normal mode - Stop recording with the
qkey again.
Nice one — we’ve recorded a macro that puts a X at the start and the end of the cursor line.
Now try moving to the second line and typing @a in normal mode.
Wow! Did you see that? The macro did all the hard work for us!
Now that we know the basics of how to use macros, we’ll delve into them in a bit more details in the coming sections.