76

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?

116

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)
3
  • 5
    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. Dec 15, 2015 at 15:30
  • 13
    @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, 2015 at 15:38
  • 3
    Thank you! I went with your solution: github.com/ryanpcmcquen/linuxTweaks/blob/master/.vimrc Dec 16, 2015 at 16:15
0

To clarify some concepts:

ten types of registers

  • The unnamed/default register ""
    - It is like the unnamed register is pointing to the last used register. (if no other register is explicitly invoke, point to "" itself)

  • 26 named registers "a to "z , or "A to "Z

  • The selection registers "* and "+

  • 10 numbered registers "0 to "9
    - "0 can be regarded as a yank register
    - "1 to "9: I call them stack_trash register (You can use this to reverse-order a handful of lines: dddddd"1p.. )

  • The small delete register "-

  • Three read-only registers ": ". "%

  • Alternate buffer register "#

    • you can think of it as the last edited file. some people say it is not frequently used
  • The expression register "=

  • The black hole register "_

  • Last search pattern register "/

X11 selection mechanism

:h clipboard-x11 , or :h x11-selection

X11 clipboard providers store text in "selections".
Selections are owned by an application, so when the application gets closed, the selection text (itself) is lost. (but it is copied in a X11 clipboard provider)

The contents of selections are held by the originating application (e.g., upon a copy), and only passed to another application when that other application requests them (e.g., upon a paste).

h: primary-selection, or :h quotestar, or :h quoteplus

There are three documented X11 selections:

  • CLIPBOARD (must all uppercase?) is typically used in X11 applications for copy/paste operations (CTRL-c/CTRL-v),
  • PRIMARY is used for the last selected text, which is generally inserted with the middle mouse button.

Nvim's X11 clipboard providers only use the PRIMARY selection and CLIPBOARD selection, for the "*" and "+" registers, respectively.

Paste vs Clipboard

Paste                                                   provider-paste paste

"Paste" is a separate concept from clipboard: paste means "dump a bunch of
text to the editor", whereas clipboard provides features like quote-+ to get
and set the OS clipboard directly.  For example, middle-click or CTRL-SHIFT-v
(macOS: CMD-v) in your terminal is "paste", not "clipboard": the terminal
application (Nvim) just gets a stream of text, it does not interact with the
clipboard directly.

:checkhealth , and I find Clipboard in provider section, but no Paste

## tmux
  - OK: escape-time: 0
  - INFO: Checking stuff
  - OK: focus-events: on
  - INFO: $TERM: screen-256color

provider: health#provider#check
========================================================================
## Clipboard (optional)
  - OK: Clipboard tool found: myClipboard

I have set g: clipboard, so there is "myClipboard" instead of xclip, nor xsel, nor tmux

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.