10

"*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?

3
  • Note that that help excerpt is from gui_x11.txt. If you're not using the X Window System aka X GUI aka X aka X11 (if you were you might have recognized 'X selections') then there's really nothing in there that you should pay attention to.
    – B Layer
    Commented Dec 9, 2019 at 3:35
  • 1
    You forgot aka Xorg @BLayer 🙃😆 Commented Dec 9, 2019 at 6:24
  • 1
    Required reading
    – muru
    Commented Dec 9, 2019 at 9:53

2 Answers 2

14

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.

7

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.

2
  • "currently selected text" does this mean that if I use my mouse to select some text in the terminal window, "+ contains that text?
    – user9024
    Commented Dec 8, 2019 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). Commented Dec 9, 2019 at 6:22

Your Answer

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