-
Make sure you have a clipboard-aware Vim build. I recommend MacVim.
-
Install or update XQuartz.app and start it.
-
In the Preferences window, activate clipboard synchronization.
-
Quit XQuartz.app.
-
In iTerm.app or Terminal.app, connect to your remote machine with:
$ ssh -X username@host
and see the XQuartz.app icon pop-up in your Dock.
From now on, XQuartz.app will start automatically in the background when you use the -X
flag, taking care of the clipboard synchronization for you.
-
If you don't already have it, install GVim. On Debian-based systems, use:
$ sudo apt-get install vim-gtk
The idea is not to use Gvim but installing it gets you everything you need to get clipboard sharing to work:
- a minimal X
- a Vim built with clipboard support
-
In Vim, synchronize the unnamed and clipboard registers by adding this line to
~/.vimrc
:set clipboard^=unnamed
After a TON of trial and error, I got it to work on both Ubuntu Server 18.04 and 20.04. I tried so many things that I eventually lost track of what the winning combo was :( One thing to note is that it worked after I uninstalled XQuartz via homebrew and reinstalled from the downloaded disk image though I'd be surprised if that was the key. I also restarted my computer at some point after that. For reference, here are the salient versions/packages that I had installed when remote-to-local copy/paste started working though, again, I don't know what the winning combo was:
... and I use the following in the .vimrc file:
I'll try and narrow down the exact combo of requirements in the future.
@romainl I find I can paste stuff copied from local into the remote vim by just going into insert mode and using cmd+v.