DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Cygwin与Windows间的Copy/Paste


命令行状态下

首先将Cygwin设为左键选择后自动复制,右键粘贴;然后就可以把Cygwin当成一个普通的Windows应用了;

vi窗口中

根据http://vim.wikia.com/wiki/Using_the_Windows_clipboard_in_Cygwin_Vim的介绍,将下面的代码拷贝到cygwin的$HOME/.vimrc中,就可以用\y拷贝,\p粘贴了。

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 system('putclip', @@) "As of Cygwin 1.7.13, the /dev/clipboard device was added to provide "access to the native Windows clipboard. It provides the added benefit "of supporting utf-8 characters which putclip currently does not. Based "on a tip from John Beckett, use the following: call writefile(split(@@,"\n"), '/dev/clipboard') let &selection = sel_save let @@ = reg_save endfunction vnoremap y :call Putclip(visualmode(), 1) nnoremap y :call Putclip('n', 1) function! Getclip() let reg_save = @@ "let @@ = system('getclip') "Much like Putclip(), using the /dev/clipboard device to access to the "native Windows clipboard for Cygwin 1.7.13 and above. It provides the "added benefit of supporting utf-8 characters which getclip currently does "not. Based again on a tip from John Beckett, use the following: let @@ = join(readfile('/dev/clipboard'), "\n") setlocal paste exe 'normal p' setlocal nopaste let @@ = reg_save endfunction nnoremap p :call Getclip()



Published

Dec 29, 2012

Last Updated

Dec 29, 2012

Category

Tech

Tags

  • copy 6
  • cygwin 5
  • Windows 67

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor