Before you start…
Macros let you record a key sequence then play it again on different text.
To start recording a macro, type
q then the register you want to save it to. It's easy to just do
Next, you type the key sequence you want to save, then hit
q again to stop recording.
To play your macro, type
@q. To keep playing it, you can use the
. command (this always repeats your last command).
You can also play a macro across a visual selection. Just make the selection, then type
:normal @q. The normal stands for Normal mode. Note that you won't actually see the
: after you type it, you'll see
'<,>' intead since you will be in visual selection mode.
Here's a quick recap:
qto stop recording
@qto play the macro
- Start recording macro in "q" register
- Stop recording macro
- Play "q" macro
- :normal @q
- Play "q" macro across visual selection