Vim allows recording a batch of commands as a macro. This is handy if you need to do the same things over and over.
Here is how:
- Press
q
to enter macro mode. - Press a letter (not a number!) key to assign a slot to your macro.
- You are now recording. Do whatever you want with usual commands.
- Once you are done, press
q
again to stop recording. - You can now run your recorded macro by pressing
@
and its assigned letter key.
Cheats:
- If you want to run a macro repeatedly, type a number before pressing the
@
key. Example:23@a
will repeat macro "a
" 23 times. - Press
@@
to repeat the last macro. This does not work instantly after recording, you need explicitly call the macro once. - You can combine the above:
42@@
calls the last run macro 42 times.
If you want to repeat only the last command, you don't need a macro. Just press the .
(period).
Posted by Arne Hartherz to makandra dev (2011-08-02 08:41)