Question

I'm using:

set clipboard=unnamed  

So that cut and copied selections go to the * register, which is conveniently linked to the x clipboard (I'm using Linux).

I would like to have it also in the + register to get both middle-mouse-pasting and Ctrl-V giving the same results in other applications. I guess this might related to the difference between xclip and xclip -selection c.

For now my workaround is:

noremap Y "+y  

So that I could do Yy to copy the current line to + register and then use Ctlr-V in some applications. But then I have to think in advance if I will use the mouse or Ctrl-V.

Is there a way I could have the + and * registers have the same value when I yank or when I select some text with the mouse?

Was it helpful?

Solution

I think you want to

:set clipboard+=unnamed,unnamedplus

From the help:

unnamedplus A variant of "unnamed" flag which uses the clipboard register '+' (|quoteplus|) instead of register '*' for all operations except yank. Yank shall copy the text into register '+' and also into '*' when "unnamed" is included.

Note that you need a fairly new Vim 7.3 (patchlevel 151?) for this option value.

OTHER TIPS

Thinking out of the box, you can install autocutsel which sinchronizes both clipboards.

As discussed in the comments, here's a solution:

vnoremap Y ygv"+y

However that does not work, only the other way around:

vnoremap Y "+ygvy

Here's what it does:

noremap Y: Map to the Y key, using default behavior of keybindings. :h noremap
"+y: Yank into + register.
gv: Re-select previous visual selection.
y: A normal yank into the * register (in Linux).

Glad I was able to help you solve it. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top