vimtricks.wiki Concise Vim tricks, one at a time.

How do I record a macro directly into the system clipboard register?

Answer

"+q{keys}q

Explanation

You can record macros into any register, including the system clipboard (+). This allows you to record a keystroke sequence and immediately have it available for pasting into other applications, documentation, or sharing with colleagues.

How it works

  • q+ — start recording a macro into the + (system clipboard) register
  • Type your keystrokes
  • q — stop recording
  • The recorded keystrokes are now in the system clipboard

Example

" Record a macro to the clipboard
q+dwwP~q

" The clipboard now contains: dwwP~
" You can paste this into documentation or another Vim instance
Alternatively, record normally then copy:
qa...q
:let @+ = @a

Tips

  • Use "* register instead of "+ on some systems (X11 primary selection)
  • Record to a named register first, then copy: :let @+ = @a
  • Import a macro from clipboard: :let @a = @+ then @a to execute
  • This is great for sharing exact keystroke sequences with team members

Next

How do I return to normal mode from absolutely any mode in Vim?