vim What is a macro?


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:


That macro could be recorded into register q:

qq         start recording into register q
q          stop recording

or saved directly into register q:

:let @q = '0wwgUiw'

to be played back with:


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:


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:


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.