← All lessons

17. Macros

Step 3 of 5

What’s in a name?

I mentioned in the previous sections that qa in normal mode starts recording a macro called a. This isn’t strictly the truth.

Vim doesn’t have a special “data store” for macros. It actually re-uses the registers that we already know about! What I mean by this is: when you start recording a macro using something like qa, Vim actually starts recording your macro into the "a register. Once you’ve finished recording, the "a macro will contain the keystrokes that you used.

So really, when you type qx, you’re actually telling Vim: “start recording a macro into the "x register”

Let’s prove it in the editor. Record a macro into the "x register with qx. Once you’ve finished recording, list the "x register with :reg x. You should notice that the "x register contains precisely the keystrokes that you in putted whilst recording.

Loading editor…