How does one append to the clipboard register in vim?

1

1

I already know that you can copy something the a register using: (plus a yank, delete, etc. command)

"a

I also understand that you can append to the a register using:

"A

In addition I understand how to copy something to the clipboard register using:

"+

The question Here is what do I type to append to the clipboard register?

Edit: This probably shouldn't be necessary but my VIM version is:

Vi IMproved 7.4 (2013 Aug 10, compiled Jan 2 2014 19:39:59) Huge version with GTK2 GUI.

Jason Basanese

Posted 2015-07-04T03:37:43.373

Reputation: 221

This shouldn't be necessary but here is the my vim version. – Jason Basanese – 2015-07-04T03:39:33.950

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan 2 2014 19:39:59) Huge version with GTK2 GUI. – Jason Basanese – 2015-07-04T03:39:41.193

See [so] duplicate question VIM: append to clipboard

– DavidPostill – 2015-07-04T12:42:56.307

1I don't see how that is a duplicate, I don't understand the @ character or the let command. – Jason Basanese – 2015-07-04T21:17:58.583

Answers

2

You have to use

:let @+ .= your_expression

see stackoverflow. The problem, as you have understood, is that you cannot capitalise the + character.

For example, to add a line in your buffer to the clipboard, place the cursor on the line and yank it with yy. Then type :let @+ .= @0 to run (:) the command let to append (.=) register (@) 0, which always holds the last yank, to register + which is a representation of the clipboard.

For example, to add the string "abc" to the clipboard, type :let @+ .= 'abc'.

(To change the X11 selection instead of the clipboard register + use register *).

vim has a huge set of commands. If you plan to adopt it as your favourite editor it is worth putting some effort into knowing, at least superficially, some of them. Most vim users probably only use about a dozen commands and are not interested it its true potential. It's a pity, as such tools could significantly reduce their workload.

You might like Learn Vimscript the Hard Way. The builtin vim help is also viewable on the web at sourceforge , with this page on The Vim script language.

meuh

Posted 2015-07-04T03:37:43.373

Reputation: 4 273

1An answer in the format of my question would be appreciated. I don't know what the let command nor the @ sign mean nor do. An explanation would be much appreciated. Would I do "+ . ? – Jason Basanese – 2015-07-04T21:21:13.500

1

Only the 26 named registers a to z can be appended to. But the "unnamed" register " always points to the last used register. We can use this to our advantage because this also means that the item appended to a named register is also appended to the "unnamed" register.

Here's an example:

1| Line 1
2| Line 2
3| Line 3
  1. Yank Line 1. "+yy.
    • Check the registers with :reg + ".
    • You'll notice they both contain Line 1.
  2. Append Line 2 to register "a" by typing "Ayy. (Or use any named register you wish).
    • Check the registers with :reg a + ".
    • Register + remains the same as expected.
    • Register a has Line 2 appended to whatever was there before.
    • Register " has both Line 1 and Line 2.

:help quotequote


Side note: look into setting the "unnamed" register to the clipboard so you don't have to type "+yy each time. If set, you can just use yy to yank to the clipboard.
:help clipboard
:help 'clipboard'
:help clipboard-unnamedplus
:help clipboard-unnamed

Matt Walsh

Posted 2015-07-04T03:37:43.373

Reputation: 11