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

6,071

Solution 1

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.

Solution 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

Solution 3

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.

Share:
6,071

Related videos on Youtube

Obi Wan Kenobi
Author by

Obi Wan Kenobi

Updated on September 18, 2022

Comments

  • Obi Wan Kenobi
    Obi Wan Kenobi over 1 year

    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.

  • UNK
    UNK almost 13 years
    @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?
  • WEBjuju
    WEBjuju about 5 years
    this is the right solution. (at least...on windows server 2012r2 cygwin 3.0.1 vim 8.0.1567).