IT WORKS! <sfx: evil genius laugh />
A few pieces are required to get smooth integration of the local OSX clipboard with the remote vim clipboard. I'll walk you through the configurations and you'll be cutting-and-pasting like it's no big thang. Pasting large blocks of text works so much better via
"+p than via system paste into an xterm vim window.
- OSX clipboard syncing with the local X11
- X11 forwarding in ssh
- vim compiled with with
- optional: configure vim to use xterm clipboard by default
- optional: a better OSX terminal: iTerm2
- optional: screen + DISPLAY var
OSX clipboard sync with X11
- launch X11 (Applications::Utilities::X11)
- open pasteboard preferences (X11::preferences::Pasteboard)
- enable syncing,
update Pasteboard when CLIPBOARD changes,
- update CLIPBOARD when Pasteboard changes
- you may want to quit X11 now to ensure the new settings are saved.
- Note: don't set update Pasteboard when CLIPBOARD changes, as it produces a very strange paste behavior where full lines will paste as relative.
ssh X-forwarding:You can enable this on the fly via the
sshor by adding "ForwardX11 yes" to your
.ssh/configfile. ForwardX11 can be set globally or per-host.
Example .ssh/config entry for my vm:
The forwarding provided via ForwardXll is seen as untrusted by the X Security extension. Untrusted clients have several limitations: they can't send synthetic events or read data from other windows and are time limited.
host vm53 user vm53 ForwardX11 yes
If you really trust the remote host you can use Trusted forwarding. This is enabled with the
-Y flag to
ssh or the "ForwardX11Trusted true" option in
.ssh/config. I've switched to using trusted connections when connecting to my local VM since my connections are open for days/weeks at a time.
host vm53 user vm53 ForwardX11Trusted true
Vim with +xterm_clipboardCheck the capabilities of your vim via
vim --version, you're looking for +xterm_clipboard.
If your version of vim doesn't have xterm_clipboard, try another package. I'm using
vm53% vim --version | grep xterm_clipboard +xsmp_interact +xterm_clipboard -xterm_save
vim-noxfor my debian/ubuntu machines.
At this point, you should be able to cut and paste using the
+ buffer to interact with the system clipboard. Paste with
"+p and copy/yank with
"+y. Under X the clipboard is in the "+" buffer, under windows it is the "*" buffer. In OSX gvim, "+" and "*" appear to be the same buffer?
configure vim to use xterm clipboard by defaultRemembering to use the
+buffer is extra work. We can make this automatic by setting the
clipboardoption in vim.
set clipboard=unnamedplus(added in Vim 7.3.074) to use the system clipboard when using the default (unnamed) buffer. At this point,
pwill paste from the system clipboard. AMAZING!
iTerm2You should ditch the default Terminal app that comes with OSX and use iTerm2 instead. You can have it do "copy on select," just as you'd expect from an Xterm, and it all ties into the work we did above. It also has some other interesting features, like native tmux support.
DISPLAY env with screenWhen reconnecting to your remote screen session, you may end up with the DISPLAY variable out-of-sync. By default, I get
DISPLAY=localhost:10.0when I connect to my VM. But each connection opens a new back channel on a new port :11.0, :12.0, etc. You may need to update the value of DISPLAY inside your screen session, via
export DISPLAY=localhost:10.0with the correct DISPLAY value for this ssh connection -- check
env DISPLAYoutside of the screen session to get the value.
P.S.I had some troubles testing until I realized I was expecting select-to-copy behavior in Chrome Browser under OSX. Ha! I'm glad I finally spent the 20 minutes to get all these pieces aligned.
UpdateUpdated to show that X users want the
+buffer rather than the
*buffer, after reading up on the original patch.
UpdateUpdated with -Y/X11ForwardTrusted information.
Updated to warn against "update pasteboard" option in OSX X11 app