Sharing your system clipboard
27 Aug 2015Today I ran into an issue that had me spinning my wheels for a little too long. I’m making it a habit to write down these moments so a.) maybe someone out there might waste less time than I did and b.) I’m sure I’ll have to come back to this at some point!
Today, I was ssh’d into a remote server and tried to yank something out of vim and into another vim running on my local machine. To clarify:
On the remote(Ubuntu): vim -> yank
On my local(OSX): vim -> paste
I quickly realized that yanking on a remote machine does not mean it will end up on my system(OSX) clipboard. That would be too easy. After some endless googling and bugging people in #vim #tmux and #ubuntu I got no where. That was until I found this post.
There’s some additional set up beyond that post so I hope this to be all encompassing, here we go:
OSX Set up
First you need to be using MacVim on OSX, I wasn’t. MacVim comes with nearly all the extra packages, but the most important one here is +clipboard . You can check if you have that already by running:
From here forward, I’ll assume you’re using MacVim. I was a little hesitant at first too but you can run MacVim in a terminal by using:
Here’s what I have in my ~/.zshrc for helpers:
Ok, now following garyjohn’s instructions, let’s open up ~/.ssh/config in vim:
Let’s copy in:
That’s it for OSX.
Remote (ie Ubuntu, Linux, *Nix, Debian, etc)
You’ll need appropriate permissions, so either run as root or have sudo access.
First a lot of distro’s come with a pre-installed version of VIM, unfortunately like OSX they usually don’t have the write packages installed which is 50% of our issue(s). I recommend the following:
If you run vim –version you should see the gtk package ships with most of the extra options for vim, including +clipboard and +xterm_clipboard.
Let’s head into /etc/ssh/sshd_config
In there put:
We’re ready to yank. Let’s try a line in some file
Open vim locally and paste, with p. There you have it, we just copy & pasted from a remote ssh session to your local vim.