Write to two registers at the same time in Vim

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?

Answer

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.