Executing Neovim Macros

Once a macro is stored in a register, it can be executed using the pattern

@{name}

where name is the name of the register that holds the macro.

counts can be used when executing macros, so to run the same macro multiple times one can use:

{count}@{name}

After a macro has been executed, one can repeat it using the shortcut @@.

In order to make macro execution as safe as possible, macro execution will stop at the occurrence of the first error.

Starting from the last step of the recording macros section, our buffer should look like this:

Initial Conditions
<p>·Beautiful·is·better·than·ugly.·<\p>
Explicit·is·better·than·implicit.
Simple·is·better·than·complex.
Complex·is·better·than·complicated.
Flat·is·better·than·nested.
NORMAL
Top
1:35
 

Now, lets execute our macro and see it in action. First hit j to go down one line, then @a to execute the macro:

Move down one line and execute the macro
j@a
<p>·Beautiful·is·better·than·ugly.·<\p>
<p>·Explicit·is·better·than·implicit.·<\p>
Simple·is·better·than·complex.
Complex·is·better·than·complicated.
Flat·is·better·than·nested.
NORMAL
33%
2:38
 

and lets repeat that one more time:

Move down one line and execute the macro
j@a
<p>·Beautiful·is·better·than·ugly.·<\p>
<p>·Explicit·is·better·than·implicit.·<\p>
<p>·Simple·is·better·than·complex.·<\p>
Complex·is·better·than·complicated.
Flat·is·better·than·nested.
NORMAL
50%
3:35
 

The macro is executing, but we overlooked two things:

  1. There are spaces between the tags and the text inside them, and

  2. Since we have to hit j between invocation of the macro, it would be more convenient to add this step to the macro itself.

Lets undo these changes, then look at how to edit macros to make these changes.

Undo
2u
<p>·Beautiful·is·better·than·ugly.·<\p>
Explicit·is·better·than·implicit. 
Simple·is·better·than·complex.
Complex·is·better·than·complicated.
Flat·is·better·than·nested.
NORMAL
33%
2:33
12 changes; before #5 0 seconds ago