Vim Tips Wiki
Register
Advertisement

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 1249 Printable Monobook Previous Next

created 2006 · complexity basic · author Gerald Lai · version 5.7


One of Vim's best features is being able to record keystrokes and play them back repeatedly. To record keystrokes, the "q" key is used.

In the spirit of VimTip398, here's another suggestion for quick and easy playback. Place in vimrc:

:noremap Q @q

This allows playback of the recording that was put into the q register.

Example of recording and playback usage:

  • Begin recording keystrokes by typing "qq".
  • Perform your customized keystrokes.
  • To end recording, type
q               in normal/visual mode
Ctrl-o q        in insert mode
  • To playback recording, hit the Caps Lock key and use "Q" in normal/visual mode. The Caps Lock key acts as a flip switch between recording and playback.

Playback can accept a count. For example, "5Q" repeats the recorded keystrokes 5 times.

If you'd still like to access Ex-mode like it was with the default "Q", use "gQ" instead. It has more features than the original Ex-mode.

References[]

Comments[]

I do the same thing except I map @a, @b and @c to the function keys F2, F3 and F4. This way it's even less keystrokes plus you can have three macros at your fingertips instead of just the one.

To map the F2 function key, put this in your vimrc file:

nmap <F2> @a

Or map F2 to @@. That way you only have to invoke a macro once explicitly like @a, then repeat it by pressing F2.


Advertisement