I am using Linux OS. I would like to copy some text in visual mode from Vim to system clipboard and then paste it in another shell. I tried the following :

In the .vimrc file inside /home/{USER} directory put the following :

vmap <C-c> "*y

After this I exited the shell and then opened a new shell and a file in vim. Did Visual selection and then issued *y. It yanked the lines selected. I exited vim and then in the shell issued CTRL+SHIFT+V . But nothing happens.

I tried setting the following also in .vimrc file :

set clipboard=unnamed

But this also doesn't work.

P.S: I am able to paste from system clipboard to vim using *p.

What can be the problem here? Am I setting the options in the wrong .vimrc file?

Edit: When I did vim --version|grep clipboard I see the following:

[subhrcho@slc04lyo ~]$ vim --version|grep clipboard
-clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments 
-xterm_clipboard -xterm_save 
  • This is the right ~/.vimrc. Try "+y and "+p instead. – romainl Apr 4 '13 at 14:33
  • @romainl *p works for me already. – Geek Apr 4 '13 at 14:36
  • Are you running vim within the terminal or the GUI version? What does vim --version | grep clipboard say? – devnull Apr 4 '13 at 14:56
  • I can read, thanks. Can you answer my question? – romainl Apr 4 '13 at 15:33

On Linux, there's a difference between "* and "+. If you want to use the system clipboard (e.g. with Ctrl + Shift + V), you have to use "+. (Likewise, there's a :set clipboard+=unnamedplus in recent Vim versions.)

To paste the contents of "* in a terminal, use the middle mouse button.

Read more about this at :help x11-selection

  • @Igno I tried your suggestion. When inside Vim , if I do +y I see vim yanks some lines. And next I quit vim by :q! and then in the shell I do a right click, I see both copy and paste context menus are disabled. The CTRL+SHIFT+V also doesn't work. – Geek Apr 4 '13 at 19:48
  • As per your edit, you first need to use a Vim that has clipboard support compiled in. Without that, you need to resort to external solutions like xclip. – Ingo Karkat Apr 5 '13 at 6:38

No. You can't paste with "*p if Vim was not build with clipboard support.

-clipboard and -xterm_clipboard mean "no clipboard". Without clipboard support, "*y, "+y, "*p and "+p can't paste to/from the clipboard at all.

If you want clipboard support, you must get yourself a proper Vim build (vim-gtk for example). It's as simple as that.

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.