Perfect Cut Copy Paste With Gvim

If you've ever wanted to copy and paste in Gvim with standard windows hotkeys using the system clipboard, just put the following in your .vimrc file.  I've seen several tips similar to this one, but the copy and pasting often comes out slightly wrong.  I guarantee these commands to work exactly how you'd expect.

vmap <C-c> "+yi
vmap <C-x> "+c
vmap <C-v> c<ESC>"+p
imap <C-v> <ESC>"+pa

Explanation:
1) Copy - When text is highlighted (Visual Mode), Ctrl-C will copy the highlighted text to the + register (system clipboard).
2) Cut - When text is highlighted, Ctrl-X will cut the highlighted text.
3) Paste (visual), When text is highlighted, Ctrl-V will paste over the currently highlighted text.
4) Paste (insert), When in insert mode, Ctrl-V will paste.

NOTE: There is no command to paste text while in normal mode.  This is because Ctrl-V is reserved for Blockwise Visual Mode, and also because it's completely unnecessary.  Copy and Cut are designed to end up in insert mode, so you can cut/copy then paste immediately.  If you try it out, you'll see that it feels completely natural!

Comments

Popular posts from this blog

Terminate Scripted Minicom Session

What Twitter Tells Us

CodinGame: Building an AI to play (and win) at "Penguins"