87

What is the difference between these 2 settings?

set clipboard=unnamed
set clipboard=unnamedplus

Which one should I use in order to have multi-platform .vimrc?

syntagma
  • 23,346
  • 16
  • 78
  • 134

1 Answers1

134

On Mac OS X and Windows, the * and + registers both point to the system clipboard so unnamed and unnamedplus have the same effect: the unnamed register is synchronized with the system clipboard.

On Linux, you have essentially two clipboards: one is pretty much the same as in the other OSes (CtrlC and CtrlV in other programs, mapped to register + in Vim), the other is the "selection" clipboard (mapped to register * in Vim).

Using only unnamedplus on Linux, Windows and Mac OS X allows you to:

  • CtrlC in other programs and put in Vim with p on all three platforms,
  • yank in Vim with y and CtrlV in other programs on all three platforms.

If you also want to use Linux's "selection" clipboard, you will also need unnamed.

Here is a cross-platform value:

set clipboard^=unnamed,unnamedplus

Reference:

:h 'clipboard'
(and follow the tags)
romainl
  • 186,200
  • 21
  • 280
  • 313
  • 12
    What is the difference here vs `^=` & `+=`? I understand from reading the vim help sections, that `^` multiplies values and `+` adds values, so to me it seems like `+` should be used, but I don't pretend to understand vim. – ryanpcmcquen Dec 15 '15 at 15:30
  • 21
    @ryanpcmcquen, Vim as three types of options: "string", "number", and "boolean". `^=` multiplies only in the context of "number" options but `'clipboard'` is a "string" option where `^=` *prepends* the value and `+=` *appends* the value. – romainl Dec 15 '15 at 15:38
  • 3
    Thank you! I went with your solution: https://github.com/ryanpcmcquen/linuxTweaks/blob/master/.vimrc – ryanpcmcquen Dec 16 '15 at 16:15
  • `"*` is the one similar to ctrl+c. `"+` is the X selection buffer. – gabriel Aug 23 '22 at 13:57
  • 5
    So, for Neovim: `vim.opt.clipboard:append { 'unnamed', 'unnamedplus' }` – Martin Braun Sep 22 '22 at 15:22