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

How do I execute the contents of the system clipboard as a Vim macro?

Answer

@+

Explanation

In Vim, @{register} executes the contents of any register as a macro. Since + is the system clipboard register, @+ runs whatever text is currently on your clipboard as a sequence of Vim keystrokes. This opens up a powerful workflow: craft a macro in a terminal, a text editor, or even a browser, copy it to the clipboard, then execute it directly in Vim without recording it manually.

How it works

  • @ — execute register as a macro
  • + — the system clipboard register (requires Vim compiled with +clipboard; use * on X11 for primary selection)

The clipboard text is replayed exactly as if you had typed those keys in normal mode, including Ex commands like :s/foo/bar<CR>.

Example

Suppose you want to run a complex sequence on several files. Prepare the keystrokes in a text editor:

:%s/oldName/newName/g
:w

Copy this to your clipboard, then in Vim:

@+

This executes the substitution and saves the file — without ever recording a macro inside Vim.

Tips

  • On X11 systems, @* runs the primary selection (highlighted text) as a macro
  • Use 2@+ to repeat the clipboard macro on 2 lines
  • After @+, use @@ to re-run the same macro again
  • Verify clipboard support with :echo has('clipboard') — returns 1 if available
  • Useful for sharing repeatable Vim operations: just paste the keystrokes in a chat message, copy, and @+

Next

How do I insert all completion matches at once on the command line instead of cycling through them one by one?