Sunday, September 2, 2007

VIMTip from a while back

I figured out how to get vim to interact reliably with the clipboard to allow users to copy and paste from vim on an intra-line level. The only tricks I had seen before restricted copy+pasting to the line level (blah). So here's a link to the vimtip. On OS X, it looks something like:
vmap <C-c> y:call system("pbcopy", getreg("\""))<CR>
nmap <C-v> :call setreg("\"",system("pbpaste"))<CR>p
This basically sets it up so that when you select any shape in visual mode (visual-blocks too), pressing Ctrl-C (not Cmd), will send that chunk of text the system clipboard.

There is also a mechanic for making it work with Linux as well. I've toyed with the idea of making it copy on every y/d/c/s as well, but I do that enough that it would destroy the system clipboard every time I used vim :P. Oh well.

No comments: