Linux – In Vim what is the difference between “+ and ”* registers

linuxvimvimrc

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?

Best Answer

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:

Related Question