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?

3 Answers 3


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, 2018 at 14:22
  • 2
    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. Mar 9, 2018 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.