Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use X11 forwarding to copy from vim to local machine

I swear I have read every single post and have not found a comprehensive solution that works for me yet. Here is what I have done so far:

  1. Configured vim to copy to system's clipboard. set clipboard=unnamedplus
  2. Enabled X11 forwarding on my remote machine.
  3. Installed xclip (https://defuse.ca/blog/clipboard-over-ssh-with-vim.html)
  4. Installed XQuartz on my local mac that I am using
  5. I am sshing into the remote Linux server as : ssh -X user@machine (XQuarz pops out)
  6. I am opening a file in vim. Yanking. CmndV into my local browser. Nothing happens.

HELP?

like image 554
doubleOK Avatar asked Oct 21 '25 19:10

doubleOK


1 Answers

From this gist:

On the Mac

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

  2. In the Preferences window, activate clipboard synchronization.

  3. Quit XQuartz.app.

  4. 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
    
like image 186
romainl Avatar answered Oct 24 '25 21:10

romainl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!