In Vim what is the difference between "+ and "* registers?

4

In Vim what is the difference between "+ and "* registers? Which one should be used for copying from and pasting to Vim from other applications? Do I need to append anything in .vimrc file to get those two registers to work?

Geek

Posted 2013-07-25T18:17:43.063

Reputation: 1 251

Answers

8

The registers are an X11 feature; they are not Linux-specific or even Unix-specific but work on any OS that uses X11.

As described in Vim documentation (:help quoteplus), the "+ register corresponds to the 'CLIPBOARD' selection in X11, while the "* register corresponds to the 'PRIMARY' selection.

  • More detailed explanation:

    The X11 graphical environment has support for multiple clipboard-like buffers, called selections. There are three standard ones, two of which are in wide use:

    • The PRIMARY selection is updated every time you select text. To paste from it (in graphical programs), middle-click or use ShiftInsert. In Vim, it is accessible through the "* register.

    • The CLIPBOARD selection is updated when you explicitly cut or copy anything (text or other data). In other words, it is used just like the Windows or Mac OS clipboards. To paste from it, the usual shortcut is CtrlV in grapical programs. In Vim, it is accessible through the "+ register.

You don't need any special settings to use them; however, your Vim must be configured with X11 support (look for +X11 in vim --version), and – obviously – the registers only work inside X11.

It doesn't matter whether you are using the GUI or terminal version of Vim, however. (On Arch Linux, the gvim package provides both GUI and terminal versions with the X11 support enabled.)

Resources:

user1686

Posted 2013-07-25T18:17:43.063

Reputation: 283 655

What is the definition of X11? – Geek – 2013-07-25T19:06:57.490

X11 aka X Window System 11 is the system and protocol used for the graphical interfaces in Linux, BSDs, most other Unix-like operating systems, as well as a few others like OpenVMS. (Surely, as a Geek, you should be able to figure that one out...) – user1686 – 2013-07-25T19:48:41.333

I have been using :r! xclip to get what has always been in "+ and "*. facepalm – Ярослав Рахматуллин – 2013-07-26T10:53:45.253