Thursday, September 16, 2010

Clipboard functionality on Unix/Windows

So after struggling for a while trying to integrate vi with the system
clipboard, I figured it out, and thought I might share it with others

On Windows (from cygwin):
vmap <C-c> :<Esc>`>a<CR><Esc>mx`<i<CR><Esc>my'xk$v'y!cat >/dev/clipboard<CR>u

On Linux machines (if you have xclip):
vmap <C-c> :<Esc>`>a<CR><Esc>mx`<i<CR><Esc>my'xk$v'y!xclip -selection c<CR>u

I think to copy only part of the line, I had to use marks to keep
track of the selection length, otherwise the cat or xclip command is
executed on the whole line. Also copying wiped out the line that I
was on, so I had to undo the command after the copy.
I think there is a buffer in vi that corresponds to the system
clipboard, but couldn't get that to work either. Yes it's an ugly
sequence of commands, but once it's in in my .vimrc I can copy and
paste from vi into other applications both on my Windows and Linux
machines

Thanks,
Ven

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: