I am unable to copy from vim to system clipboard. Viceversa works, copying from outside vim and pasting with p
is ok.
I have installed clipboard support, vim version is 7.3.429:
$ vim --version | grep clip
+clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments
+xsmp_interact +xterm_clipboard -xterm_save
I have:
set clipboard=unnamedplus
in my .vimrc
and it is set when I do:
set clipboard?
or
:echo has('clipboard')
I am using Ubuntu 12.04 LTS, and vim inside gnome-terminal
(but also GVim has the same problem). Any idea?
This is what works for me (Ubuntu 13.10):
Reinstall vim as vim-gtk:
select what you want using the mouse - then type to copy to clipboard:
to paste to vim from clipboard type:
I don't know why but comparing the output of
vim --version
shows that the usual vim installation is quite restricted compared to vim-gtk. Replacing vim with vim-gtk did not affect any plugings.Further information:
I am going to leave the original answer below because it may be important for others that search for this question.
In short there doesn't seem to be a one size fits all answer, but with 'set clipboard=unnamedplus' one of either '*p' or '+p' should work from the "system" clipboard.
'*p' is almost certainly the one you want. (from here)
vim is a cli program. When using it inside gnome-terminal (or any terminal emulator) crtl+c (or any key combination) is handled by the terminal emulator first, then the shell, then finally by the program (vim in this case). vim and ctrl+c will almost certainly never work because ctrl+c sends an SIGINT signal to the running task. vim uses SIGINT to stop other things like aborting insert mode, or stopping search functions.
In other words. Ctrl+C is never actually passed to VIM. SIGINT is passed to VIM. SIGINT has other uses in vim so using to copy is likely not going to work (and even if can you force it, not a good idea).
Instead try sticking with Ctrl+Shift+C and Ctrl+Shift+V (there are others but I believe those put text in the system clipboard)
To be fair I don't know much about gvim.
Use in your vimrc:
It will allow you to select and copy manually with mouse.
In addition to the accepted answer, if you are working remotely over SSH (e.g. over
tmux
with multiple panes with differentvim
processes you want to copy between), you also need to export your X display sincevim
is usingxterm-clipboard
to interface between different processes. You can set the X display by runningThis must be run before
vim
is launched, and under any other shell you have.I have found on Ubuntu 16.04 I need
vim-gui-common
installed in order for"+y
to work.