5

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.

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.

2
  • I tried, but it doesn't work. Thanks for the answer though. – prosseek Jul 6 '11 at 14:49
  • 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 Jul 6 '11 at 15:11
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

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.

1
  • this is the right solution. (at least...on windows server 2012r2 cygwin 3.0.1 vim 8.0.1567). – WEBjuju Mar 15 '19 at 14:53
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.

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.