CcMango
CcMango

Reputation: 437

How to display line numbers as well as enable copy to system clipboard in vim?

Local OS: Mac High Sierra

Remote OS: Linux, Debian

In vim, I'd like to enable displaying line numbers as well as enabling copy to system clipboard on both Mac and Linux. At this moment, I created the same .vimrc file in both systems with the below configurations:

set number " display line numbers
set mouse=a

I also tried set mouse=r and set mouse=v as suggested in other posts, the issue was not fixed.

Upvotes: 0

Views: 98

Answers (1)

romainl
romainl

Reputation: 196886

The local clipboard and the remote clipboard need to be synchronized for this to work. From this gist:

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
    

Upvotes: 1

Related Questions