One way to create a macro is to record it.
Start recording a macro and save it to a register (in this example, we'll use
a, but it can be any register you could normally yank text to):
Then run the commands you want to record in the macro (here, we'll surround the contents of a line with
When we're finished with the commands we want to record in the macro, stop the recording:
Now, any time we want to execute the recorded sequence of commands stored in
and vim will repeat the recorded sequence.
Next time you would like to repeat the last macro that was used you can double type
And as a extra bonus it is good to remember that if you put a number before a command it will repeat it that many times. So, you repeat the macro saved in register
a 20 times with: