Replaying macros
Once you’ve recorded a macro, you can replay it by pressing q (lowercase)
in normal mode. The pair is easy to remember: Q records, q plays.
It’s easier to see the magic of macros in practice, so let’s try this in
the editor. Work through the checklist below: record a macro that puts an
X at the start and the end of the cursor line, then move to the second
line and replay the whole edit with q.
Wow! Did you see that? The macro did all the hard work for us!
One thing to keep in mind: a replay starts from wherever your cursor happens
to be, with whatever selection you happen to have. I and A don’t care
about that, which is why this macro works on any line — but a macro that
starts with e or w will behave differently depending on where you were
standing. Starting a recording with gh (go to line start) is a cheap way to
make a macro line-proof.
Now that we know the basics of how to use macros, we’ll delve into them in a bit more detail in the coming sections.