3

On my local computer, I have the following in ~/.vimrc, which allows me use to the mouse (e.g. to select text) and to copy to the system clipboard with Ctrl+c.

set mouse=a
vnoremap <C-C> "+y

Having set mouse=a means I can copy the "real" text, rather than what the terminal interprets (e.g. with control characters and whitespace). Paradoxically, it also lets me select text without the mouse to copy. Without this setting, I need to use the mouse.

If I have these settings on a remote computer, and I enable X11 forwarding, I can also copy directly into my local clipboard.

However, I have a version of vim installed on another server compiled without +clipboard. Here, copying fails. Is it possible to copy directly into my local clipboard, while still having set mouse=a?

  • If you want to just copy the text that the terminal is displaying, you should be able to hold the alt key while selecting text. – Tommy A Jun 21 '16 at 3:17
  • @TommyA I suspect I'd probably have to settle for just copying what the terminal displays. However, that doesn't work for me (using terminator). With set mouse=a, the cursor moves to the first place I click, and nothing more happens. – Sparhawk Jun 21 '16 at 3:20
  • I'm not familiar with terminator, but there has to be an option that allows the native mouse to take precedence. If holding alt doesn't work, shift or middle/right click dragging might. – Tommy A Jun 21 '16 at 3:24
  • @TommyA Ah yes, shift works perfectly. Thank you. If you put that up as a workaround, I'll upvote it (but will delay accepting for a better solution, if it exists). TBH it is slightly better than not having set mouse=a, but still doesn't let me copy the real text, nor copy using visual mode. – Sparhawk Jun 21 '16 at 3:41
  • I'll post an answer and give a little more detail since this is something I've personally invested some time in. – Tommy A Jun 21 '16 at 4:03
4

Depending on your terminal, doing one of the following will allow you to select text that's being displayed in the terminal:

  • holding alt and dragging
  • holding shift and dragging
  • middle/right click dragging

On the more broad topic of sharing the registers between separate terminal sessions:

There is a plugin vim-fakeclip that will make use of xsel, xclip, pbcopy/pbpaste, and tmux's buffers. But, it's a little heavy handed with the keybindings and won't help over the network.

If you aren't against using Neovim, it allows a script to control how the * and + registers are stored. By default, it supports xsel, xclip, OS X's pbcopy/pbpaste, and lemonade.

I also created my own plugin that I've used for over a year now: sshclip. It's a client/server thing similar to how lemonade works, but it keeps everything encrypted on a server and uses ssh to transmit the data. I've been able to yank and paste between terminals and servers pretty reliably using this. It also works with vanilla Vim thanks to inspiration drawn from vim-fakeclip (it maps a lot in Vim). Unfortunately, I haven't made much of an effort to make it user friendly. So, I can only recommend it if you don't mind reading scripts to get an idea of how it works.

  • Thank you (+1). Your plugin looks intriguing, but a bit too intimidating for me as is! – Sparhawk Jun 21 '16 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.