Using clipboard through SSH in vim

24

15

I have Ubuntu 11.04 desktop and a 11.04 VPS server.

After replacing vim with vim-gtk (I don't need GUI though), I'm able to use the system's clipboard in vim. I'd like to use the same feature in Ubuntu server, but it looks like it doesn't work with ssh -X.

Is there some way I can enable that feature or do I need to use nano for that?

jaz

Posted 2011-08-23T12:03:50.783

Reputation: 337

related for windows host: https://stackoverflow.com/questions/4313262/copying-stuff-from-vim-running-in-putty/4313348#4313348

– Ciro Santilli 新疆改造中心法轮功六四事件 – 2017-09-17T23:07:32.833

Answers

29

The "clipboard" is a feature of X11, so you will need to enable "X11 forwarding" for the SSH connection in "trusted" mode:

$ ssh -Y myserver

(By default, X11 is forwarded in "untrusted" mode, which is somewhat too restrictive. -Y disables the restrictions.)

Also make sure the server has xauth and a X11-capable version of vim installed. You can use xsel -o and xsel -o -b to verify that the clipboard can be accessed.


To make it permanent, add the following to your local ~/.ssh/config:

Host myserver
    ForwardX11 yes
    ForwardX11Trusted yes

user1686

Posted 2011-08-23T12:03:50.783

Reputation: 283 655

For whomever it is useful for: this worked for me, but only with the + register, not the * register. Your mileage may vary. – Walt W – 2017-09-15T20:09:19.447

Does doing this mean you're actually using X-based vim, and not the command line text based Vim? – CMCDragonkai – 2019-01-20T09:13:40.897

@CMCDragonkai: No. If you run vim, you still get the text-based Vim – which just has minimal X11 support for accessing the clipboard and such. – user1686 – 2019-01-20T11:28:23.653

1I'm using vim-gtk in server and I can see using "vim --version" that X11 is enabled. There is nothing about xauth through. This is what I get: $ xsel -o xsel: Can't open display: (null) : Success – jaz – 2011-08-23T12:38:10.447

1"sudo apt-get install xauth" did the trick. – jaz – 2011-08-23T14:23:12.490