How to copy and paste between cygwin's vi/emacs and windows clipboard?

5

1

I tried to paste what I copied in windows clipboard into cygwin's vi or emacs, and it doesn't seem to work with yy (vi) or M-w (emacs).

Is there a way to do it? I learned that /etc/clipboard has the clipboard data from windows, but I don't know how to get this info in vi or emacs.

prosseek

Posted 2011-07-06T14:31:02.777

Reputation: 4 635

Answers

3

At least for vim, the clipboard is the "* register.

So, to yank the current line, go "*yy, to paste in the contents of the clipboard, go "*p, so on and so forth.

Phoshi

Posted 2011-07-06T14:31:02.777

Reputation: 22 001

I tried, but it doesn't work. Thanks for the answer though. – prosseek – 2011-07-06T14:49:05.883

1@prosseek; Oh. Well, FWIW, it works in both gvim and the version of vim that comes with it - you could consider using those over cygwin's? – Phoshi – 2011-07-06T15:11:16.800

2

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

1lOtzM291W

Posted 2011-07-06T14:31:02.777

Reputation: 121

1

There is a solution mentioned in Wikia:

function! Putclip(type, ...) range
  let sel_save = &selection
  let &selection = "inclusive"
  let reg_save = @@
  if a:type == 'n'
    silent exe a:firstline . "," . a:lastline . "y"
  elseif a:type == 'c'
    silent exe a:1 . "," . a:2 . "y"
  else
    silent exe "normal! `<" . a:type . "`>y"
  endif
  call writefile(split(@@,"\n"), '/dev/clipboard')
  let &selection = sel_save
  let @@ = reg_save
endfunction


vnoremap <silent> <leader>y :call Putclip(visualmode(), 1)<CR>
nnoremap <silent> <leader>y :call Putclip('n', 1)<CR>

just copy these lines to .vimrc and your \y will do the trick, whether you are using vim or your mouse to select texts.
This may not be a problem since you already have access to the clipboard, but /dev/clipboard is available for Cygwin version 1.7.13 and higher.

Forethinker

Posted 2011-07-06T14:31:02.777

Reputation: 640

this is the right solution. (at least...on windows server 2012r2 cygwin 3.0.1 vim 8.0.1567). – WEBjuju – 2019-03-15T14:53:12.820

0

To paste from the clipboard using vi in Cygwin:

Press SHIFT-INSERT in insert mode

(this means the insert key by the Delete/Home/End keys)

To copy to the clipboard using vi in Cygwin:

When you select text with your mouse, it automatically gets copied to the clipboard.

You can paste from the clipboard by pressing the middle mouse button.

Also, in some environments where "*yy doesn't work, you can try "+yy.

Unfortunately this does NOT work in Cygwin.

jahroy

Posted 2011-07-06T14:31:02.777

Reputation: 362