9

"*p and "+p seem to behave the same.

I tried :help "*, but it's talking about mouse selection, and :help "+ tells me

There are three documented X selections: PRIMARY (which is expected to represent the current visual selection - as in Vim's Visual mode), SECONDARY (which is ill-defined) and CLIPBOARD (which is expected to be used for cut, copy and paste operations).

Of these three, Vim uses PRIMARY when reading and writing the "* register (hence when the X11 selections are available, Vim sets a default value for 'clipboard' of "autoselect"), and CLIPBOARD when reading and writing the "+ register. Vim does not access the SECONDARY selection.

But I don't understand this; what's it got to do with visual mode? What are X selections?

9

If you're on Mac or Windows, there's no difference. On Linux they are different.

If you only work in Vim, you really don't need either of them (I mean that you can live without them), as they are best used to interact with the outside world.

Indeed, if you select something with your mouse (everywhere, not necessarily in the terminal; try by selecting some text in, say, Firefox), and then you go back to Vim, the * register will contain that thing you selected.

If instead you copy some text with Ctrl+C or equivalent (again from anywhere), and then you go back to Vim, you will find that stuff in the + register.

Clearly, if you select some text with your mouse and then you hit Ctrl+C to copy it, and then you go back to Vim, you will find the same content in both registers. There are ways, however, to copy something to the clipboard without selecting it first (think about the "copy to clipboard" buttons that you sometimes find on a website), and in those cases you can preserve the primary selection while writing to the clipboard.

BTW, in case you don't know, :reg shows the content of the registers.

| improve this answer | |
5

The PRIMARY selection contains the currently selected text. You can paste it with the middle mouse button (or Shift+Insert in some terminals).

The CLIPBOARD selection needs to be set explicitly with Control+C, and can be inserted with Control+V. This is essentially how Windows and macOS work.

I always remember because the C from CLIPBOARD is for Control+C, which contains a + like the register.

On Windows and macOS the + and * registers are the same.

| improve this answer | |
  • "currently selected text" does this mean that if I use my mouse to select some text in the terminal window, "+ contains that text? – theonlygusti Dec 8 '19 at 13:44
  • Yes @theonlygusti; kind of, anyway. The X11 clipboard actually works a bit weird (see e.g. this, the tl;dr is that on copy nothing is copied, but applications tell X11 they have a selection, and on paste the application requests the content from the application that last told X11 it had a selection). – Martin Tournoij Dec 9 '19 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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