← All lessons

17. Macros

Step 2 of 5

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:

  1. Move your cursor to the first line in the editor
  2. Record a macro called a with qa in normal mode
  3. Once you’re recording, prefix the line with a X (hint: IX), and go back to normal mode
  4. Add a X to the end of the line (hint: AX), and go back to normal mode
  5. Stop recording with the q key 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.

Loading editor…