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

How do I copy or transfer text between Vim registers?

Answer

:let @+ = @"

Explanation

Vim's :let @{reg} syntax lets you read from one register and write to another. This is especially useful for moving yanked text to the system clipboard, combining register contents, or transforming register values without re-selecting text.

How it works

  • :let @a = @b — copy the contents of register b into register a
  • :let @+ = @" — copy the unnamed (default yank) register to the system clipboard
  • :let @a = @a . @bconcatenate registers a and b, storing the result in a
  • :let @" = @/ — copy the last search pattern into the unnamed register

Register names follow Vim conventions: a-z for named registers, " for unnamed, + for system clipboard, * for primary selection, / for last search, etc.

Example

You yanked some text with yy and now want it on the system clipboard:

:let @+ = @"

Or you want to build up a register from multiple sources:

:let @a = "function " . @b . "() {\n}\n"

You can also clear a register:

:let @a = ''

Tips

  • Use :echo @a to inspect a register's contents before copying
  • :let @/ = 'pattern' sets the search register directly — useful in scripts
  • This approach is cleaner than re-yanking when you just need to move data between registers
  • Works in Ex commands, functions, and mappings

Next

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