Sometimes though it's not trivial to get a macro right from the first time. But do you know there's a simple hack to modify an already recorded macro without re-recording it?
First, a quick recap of what macro is.
Macro is a sequence of operations you can record in Vim in order to replay it later and thus automate some repetitive work.
You may know how to record a macro. You press
qa in normal mode. Then make some operations and press
q again to stop recording. Now you recorded your macro. In order to replay it, you can press
@a and then
@@ to replay the last macro. Then you can obviously run it 100 times with
Now in this case, when you press
a is a Vim register. The same register that we use for yanking and pasting. That means that after recording a macro, you can see what's inside by typing
:registers. Or by simply pasting from it
You will see that it is just a text. Whatever you type while recording a macro is stored in that register a simple sequence of letters typed.
Now the trick is that you can paste your macros into your file, then modify the sequence of operations and then yank it back with
"ay. The macro is updated and you can run it again.