Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing System Clipboard with vim under cygwin

Tags:

vim

cygwin

I built a pretty good cygwin setup under Windows7. I installed vim under cygwin. Now, I can't share the system clipboard with vim. vim --version gives:

+clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments
+xsmp_interact +xterm_clipboard -xterm_save

I tried setting set clipboard+=unnamed inside my .vimrc but it was no use. I tried P, "+p, *p and "*p but none of these pasted from the system clipboard. However, pressing SHIFT+Ins on cygwin prompt pastes from system clipboard. Am I missing something?

like image 688
abhisek Avatar asked Oct 18 '25 20:10

abhisek


2 Answers

Copy text from vim under cygwin, just press "key +key ykey in visual mode :

"+y

Paste text to vim under cygwin, just press " key +key pkey in normal mode :

"+p

like image 138
1lOtzM291W Avatar answered Oct 21 '25 15:10

1lOtzM291W


Cygwin uses /dev/clipboard to access windows clipboard. For copying in visual mode, you can just do something like:

:'<,'>w !cat > /dev/clipboard

In order to paste from a windows clipboard, you can do something like this:

:r !cat /dev/clipboard

I have been using this method for some time now without any issues. But it only works for console version of vim. Gvim for windows has + register which allows you to copy and paste from windows clipboard. So, it's as easy as "+y (copy) and "+p (paste).

Source: http://vim.wikia.com/wiki/Using_the_Windows_clipboard_in_Cygwin_Vim

like image 43
Alan Turing Avatar answered Oct 21 '25 14:10

Alan Turing