sponsor Vim development Vim logo Vim Book Ad

intermediate Tip #866: Cut/Copy(All)/Paste with Ctrl-X/C(A)/V

 tip karma   Rating 112/38, Viewed by 5766 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   February 5, 2005 18:23      complexity:   intermediate
author:   Matous Jan Fialka      as of Vim:   6.0

"<Ctrl-X> -- cut (goto visual mode and cut)

imap <C-X> <C-O>vgG
vmap <C-X> "*x<Esc>i

"<Ctrl-C> -- copy (goto visual mode and copy)

imap <C-C> <C-O>vgG
vmap <C-C> "*y<Esc>i

"<Ctrl-A> -- copy all

imap <C-A> <C-O>gg<C-O>gH<C-O>G<Esc>
vmap <C-A> <ESC>gggH<C-O>G<Esc>i

"<Ctrl-V> -- paste

nm \\paste\\ "=@*.'xy'<CR>gPFx"_2x:echo<CR>
imap <C-V> x<Esc>\\paste\\"_s
vmap <C-V> "-cx<Esc>\\paste\\"_x

Matous Jan Fialka

 rate this tip  Life Changing Helpful Unfulfilling 

<< Easy buffer switching | quickly get help on python libraries >>

Additional Notes

Anonymous, February 5, 2005 18:28
Just for including in ~/.vimrc ...
Anonymous, February 7, 2005 12:14
Whats wrong with the default:

vnonremap <silent> <C-C> "+y
vnoremap <silent> <C-X> "+x
nnoremap <silent> <SID>Paste :call <SID>Paste()<CR>
inoremap <script> <C-V> x<BS><Esc><SID>Pastegi
vnoremap <script> <C-V> "-c<Esc><SID>Paste

function! s:Paste()
let oldVE = &virtualedit
set virtualedit=all
normal `^
if @+ != ''
normal "+gP
let c = col(".")
normal i
if col(".") < c " compensate for i<ESC> moving the cursor left
normal l
let &virtualedit = oldVE
Anonymous, February 7, 2005 14:51
go back to notepad
Anonymous, February 7, 2005 16:56
It was just for my friend, I do not really need it :-) But why not to put it here? Lot of people like such strange behaviour. I have never had something called :notepad:, huh...
Anonymous, February 8, 2005 5:13
Vim neds *something* analogous to Emacs' CUA mode. I think this tip is wonderful, personally.
Anonymous, February 8, 2005 16:34
But why? Everybody can write some *tricks* in ~/.vimrc. Thus there is no need of such modes. I thing Emacs is wrong if it has only one style of... you know (poor english...)...
Anonymous, February 8, 2005 16:38
No, in Emacs CUA mode is off by default; you have to turn it on if you want to use it. (I only use Emacs for Gnus, BTW.)
Anonymous, August 10, 2005 2:11
Thank you, it is helpful for me!
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo