Skip to content

Instantly share code, notes, and snippets.

@romainl
Last active September 27, 2022 13:17
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romainl/96180b5b8e7722a7428c to your computer and use it in GitHub Desktop.
Save romainl/96180b5b8e7722a7428c to your computer and use it in GitHub Desktop.
Clipboard sharing on Mac OS X is easy

Clipboard sharing on Mac OS X is easy

On the Mac

  1. Make sure you have a clipboard-aware Vim build. I recommend MacVim.

  2. Install or update XQuartz.app and start it.

  3. In the Preferences window, activate clipboard synchronization.

  4. Quit XQuartz.app.

  5. 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.

On the remote machine

  1. 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
  2. In Vim, synchronize the unnamed and clipboard registers by adding this line to ~/.vimrc:

     set clipboard^=unnamed
    

My Vim-related gists.

@YanzhaoW
Copy link

@MagnusBrzenk Does it still work now? In my case, it works after I reinstall XQuartz. But after I exit server and close XQuartz, it doesn't work again next time I log into the server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment