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 registerbinto registera:let @+ = @"— copy the unnamed (default yank) register to the system clipboard:let @a = @a . @b— concatenate registersaandb, storing the result ina: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 @ato 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