Copy to system clipboard instead of vim buffer

19

9

I would like to set Y and P to copy and paste directly to the system clipboard instead of vim buffer.

I don't want any additional commands. Just the normal ones, but they should copy to and paste from the system clipboard and bypass the vim buffer.

How can I achieve this?

I'm running vim on Ubuntu 10.10.

Owais Lone

Posted 2010-09-11T21:20:54.333

Reputation: 303

Answers

9

You can have Vim use the clipboard instead of the default register for yanking, putting, etc., by adding this command to your ~/.vimrc:

set clipboard+=unnamed

See

:help clipboard
:help 'clipboard'

garyjohn

Posted 2010-09-11T21:20:54.333

Reputation: 29 085

I had to use set clipboard+=unnamedplus as per http://vim.wikia.com/wiki/Accessing_the_system_clipboard. The * register doesn't copy to my clipboard when I'm running vim from a terminal (which is always).

– cledoux – 2015-03-03T20:36:55.790

For Arch (around 2016-04), I did: set clipboard=unnamedplus – hodgkin-huxley – 2016-04-22T14:46:32.693

23

You first need to see if vim is compiled with clipboard support, run vim --version | grep clip and see if there is a + or - in front of clipboard and xterm-clipboard.

If it has clipboard support, copying from and pasting into the * or + registers should use the system/X11 clipboards, so "*yy would copy a line and "*p would paste it.

In Ubuntu 10.10 you can install vim-gnome to have clipboard support compiled in.

steabert

Posted 2010-09-11T21:20:54.333

Reputation: 586

3I tried both this and the method above but I can't get it to copy to system clipboard. It works fine inside Vim though. – Owais Lone – 2010-11-12T09:56:11.923

8

have a try :

"+y   and    "+p

this works for me, on Ubuntu.

wliao

Posted 2010-09-11T21:20:54.333

Reputation: 348

1This one works for me, not the * version. Why are people reporting different things? – trusktr – 2013-04-06T07:37:41.757

6

The default VIM in Ubuntu is vim-tiny, which is not compiled for system clipboard support. You need to install the full VIM and the Gnome GUI to get clipboard support:

sudo at-get install vim-full vim-gnome

After you install those two packages you can then use the commands that Akira and wliao mentioned.

dotancohen

Posted 2010-09-11T21:20:54.333

Reputation: 9 798

0

On my Ubuntu 18.04 (GNOME Shell) this enabled clipboard:

sudo apt-get install vim-gnome

vim --version|grep clipboard
+clipboard         +jumplist          +persistent_undo   +virtualedit
-ebcdic            +mouseshape        +statusline        +xterm_clipboard

MD. Mohiuddin Ahmed

Posted 2010-09-11T21:20:54.333

Reputation: 573

0

yank to the clipboard register:

 "*y

paste from the clipboard register:

 "*p

for more information:

 :help clipboard

akira

Posted 2010-09-11T21:20:54.333

Reputation: 52 754

It doesn't work. Works fine in Vim itself but does not seem to affect the system clipboard. – Owais Lone – 2010-11-10T08:11:22.693

Oh, it's not working because my version is 7.2 and this seems to be supported in 7.3 only. – Owais Lone – 2010-11-10T08:22:30.933

Then why not upgrade? – harrymc – 2010-11-29T20:33:29.273

It works for me exactly as described, except using +. "+yy.... Why? – trusktr – 2013-04-06T07:38:19.857

@trusktr: look at the answer of steabert. – akira – 2013-04-06T15:49:53.127

@akira Ahhh, that makes sense. Mine is compiled with a +. :) – trusktr – 2013-04-09T01:06:42.000