3

I'm trying to yank to the system clipboard on Ubuntu 14.04. I can't yank into the + or * registers, though. Every time I visually select my text and type "*y or "+y the indicator on the bottom right initially indicates the number of lines selected (e.g. 4) while in visual mode. After the next keystroke, ", it indicates that it is in operator pending mode (lists " instead of 4).

As soon as I press * the " changes back to the number of lines selected (4). Pressing y after this vim reports that 4 lines were yanked. But they are definitely not in the system clipboard. The exact same thing happens when I try to store the yank in the + register.

Notes:

  1. I have two keyboard layouts configured (Dvorak: primary, QWERTY: secondary). The same thing happens on both layouts.
  2. I have stripped down my .vimrc to an empty file: No luck.
  • 4
    Has your vim been compiled with the option +clipboard? You can check that with the function :version(). More precisely you can use :echo has('clipboard') to check if this precise option is enabled. If it is not you'll have to recompile a vim with this option. – statox Jul 22 '15 at 5:03
  • 1
    That's probably the problem, but you don't have to recompile to solve it. If gvim is installed, you can start it as gvim -v and get a terminal vim, or you can link gvim to vim, e.g., ln /usr/bin/gvim ~/bin/vim and make sure ~/bin is before /usr/bin in your PATH. – garyjohn Jul 22 '15 at 16:07
  • 1
    @statox: The OP didn't say whether he was using vim or gvim, but this is a commonly-encountered problem with terminal vim on Ubuntu and Fedora systems, so I assumed the OP was using terminal vim. The problem is that these distributions build their vim packages without support for X, which I don't understand. They also have separate vim and gvim packages, which I don't understand, either. Gvim, of course, has support for X. Both vim and gvim binaries can be run in either terminal mode or GUI mode, depending on how they're invoked. ... – garyjohn Jul 22 '15 at 18:35
  • 1
    ... My proposal was for the OP to run the gvim binary, which does support X and the clipboard, in terminal mode so that the clipboard will be available. – garyjohn Jul 22 '15 at 18:37
  • 1
    @statox my vim doesn't have a version() function, but it does have a :version command. Is that a typo or is my :version missing version()? – jjaderberg Jul 22 '15 at 19:24
1

@statox and @garyjohn, thank you for taking your time to answer. I looked for solutions to this problem before I posted this (I don't like wasting my time). It seems, though, that this has been asked before.

Indeed, my version of Vim seems not to have been compiled with +clipboard (I had no idea that this was even a thing... How do you guys know everything?). echo has('clipboard') returns 0.

@statox, I don't want to recompile Vim. I wouldn't be compiling it again as I downloaded a precompiled binary anyway using apt-get, the aptitude repository manager, but it would still be a pain (making would take forever for vim). So, I have installed vim-gtk and removed vim and I now have access to the system clipboard (checked over ssh). Thanks you guys for pointing me in the right direction.

There is a good StackOverflow post here that mentioned this very problem. I may have even read this yesterday when I had my problem but I don't think that I got to this really important paragraph:

Be aware that copying/pasting from the system clipboard will not work if :echo has('clipboard') returns 0. In this case, vim is not compiled with the +clipboard feature and you'll have to install a different version or recompile it. Some linux distros supply a minimal vim installation by default, but generally if you install the vim-gtk package you can get the extra features.

Thanks, again, you guys for the help.

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