This is one of the most flexible and powerful features of VIM: macros.
On day 8 I mentioned registers. To recap: VIM provides 26 registers
named a-z which can hold arbitrary text. This text can include VIM
commands. When you are in command mode, typing q followed by the name
of a register (a-z) will put you in to macro recording mode. Once this
starts, every keystroke you type will be recorded into the register that
you named.
When working with large blocks of structured text, this is insanely
productive. When you’re done typing the keystrokes that you need, hit
keystrokes are in the register and ready for playback.
Type @+
exactly the commands you typed in while recording the macro, so if you
need the cursor to drop to the next line, or if you need to search
forward for some text, make sure that you end the macro with the
appropriate keystrokes.
Since the macro is recorded to a register, the same rules of register
use apply – if you want to append keystrokes to an existing macro that
was recorded in register a, you can add more commands by typing qA
(capital names append to registers).
Go crazy, and happy VIMming.
- David Roth
