# How to transfer a register to the system clipboard?

If I store a value in a register in vim, is there a way I can transfer it to the system clipboard using a quick ex command? Or do I need to write a macro to do that?

you can try :let @*=@a to assign register a to register *. Same for @+ (depending on which clipboard you want)

• Which clipboard? What do you mean by that? – leeand00 Mar 9 '18 at 14:22
• On Unix you have in the X11 server 2 clipboards, the typical one in the desktop environment (called CLIPBOARD, using CTRL-C in the DE) that would be @+ and the Selection (usually called PRIMARY, the one where you can paste with middle mouse) clipboard @* those are different there. However Windows only knows @+ and @* is the same there. – Christian Brabandt Mar 9 '18 at 14:33

While let @* and let @+ works, the recommended way to do it in the doc is to use setreg() like this:

call setreg('+', @a)


See :h setreg() which even contains an example of what you want to do:

:call setreg('*', @%, 'ac')


The third argument is used to specify the type of the register you want to copy. It is also used to append the register to the current content of the clipboard:

If {options} contains "a" or {regname} is upper case,
then the value is appended.
{options} can also contain a register type specification:
"c" or "v"          |characterwise| mode
"l" or "V"          |linewise| mode
"b" or "<CTRL-V>" |blockwise-visual| mode

let @* = @q


where q is the register in question.