Skip to content

Instantly share code, notes, and snippets.

@benjaminhawkeslewis
Created May 6, 2012 16:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjaminhawkeslewis/2623263 to your computer and use it in GitHub Desktop.
Save benjaminhawkeslewis/2623263 to your computer and use it in GitHub Desktop.
Sharing clipboards

Sharing clipboards between OS X and remote *nix

Install latest stable XQuartz.

Forward your X11 connection when SSHing to the box:

ssh -X remoteuser@remotehost

Alternatively you can configure this, globally or for an individual host, in your .ssh/config with the ForwardX11 directive.

In your X11 preferences, open the "Pasteboard" tab and ensure "Enable syncing" and "Update Pasteboard when CLIPBOARD changes" are ticked.

Access the clipboard from a remote shell

On the remote *nix box, install XClip.

Copy STDIN from your remote box to your local OS X box to XClip like so:

xclip -selection clipboard

You can paste text from your local OS X box to STDOUT on your remote box like so:

xclip -o

Access the clipboard in remote Vim

You should be able to copy text from a Vim session on your remote box to your local OS X using the quoteplus ("+) register.

For example, type "+y to copy the selection and "+p to paste the selection.

Access the clipboard from a remote Emacs launched with no-window-system

If you run Emacs with --no-window-system it has no knowledge of X11, but it still has access to the shell. You can therefore interact with the X11 clipboard using XClip, for example using xclip.el.

Access the clipboard from remote Tmux

You can use XClip with Tmux buffers, copying text:

tmux show-buffer | xclip -selection clipboard

Or pasting:

tmux set-buffer "$(xclip -o)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment