A macro is a series of keystrokes meant to be "played back" by Vim without any delay. Macros can be stored in registers or variables, bound to keys, or executed on the command line.
Here is a simple macro that uppercases the third word
on a line:
0wwgUiw
That macro could be recorded into register q
:
qq start recording into register q
0wwgUiw
q stop recording
or saved directly into register q
:
:let @q = '0wwgUiw'
to be played back with:
@q
But it could also be typed directly in the command-line:
:normal 0wwgUiw
for instant playback via the :normal
command.
Or put into a variable:
:let myvar = '0wwgUiw'
to be played back with:
@=myvar
Or saved as a mapping:
nnoremap <key> 0wwgUiw
to be played back by pressing <key>
.
If you want to store a macro for later reuse you can type in insert mode:
<C-r>q
This inserts the macro in register q
(in this example: 0wwgUiw
). You can use this
output e.g. to define the macro in your vimrc
:
let @q='0wwgUiw'
Doing so the register q
is initialized with this macro every time you start vim.