Vim Tips Wiki

Quick yank and paste

Redirected from VimTip356

1,614pages on
this wiki
Tip 356 Printable Monobook Previous Next

created 2002 · complexity basic · author Niels Aan de Brugh · version 5.7


  • I propose making this the "copy/paste mappings" tip, and merge in the various other attempts.
  • When finished, rename this tip (and maybe some of the others).
  • Possibly have a section for Windows Ctrl-C/X/V stuff, and another for other approaches.
  • For Windows Ctrl-C/X/V, is there any need for a tip other than to explain about mswin.vim?
  • The wiki should explain how to use Vim properly, so a bunch of tips on making Vim imitate Notepad are not helpful IMHO. However, one tip on Ctrl-C/X/V is warranted (particularly now they are "standard" on Mac + Windows + Linux).
  • Might keep some different approaches, but perhaps will just pick what appears to be the "best".
  • Use following list for related tips (probably will not merge them to here, but may find some info in them that could be moved to this tip).


System clipboardEdit

Content from VimTip356 (this tip)Edit

Since I didn't want to interfere with the standard Vim mappings I removed all the <C-c>, <C-v>, etc. mappings found in the default vimrc. But quickly copy-pasting text is a must, so I added the following keymaps. This is very simple, but it works like a charm.

vmap <C-Space> "ay
nmap <C-Space> "aP
imap <C-Space> <C-o>"ap
nmap <C-c> "ayiw


I found the insertion mapping faulty: its behavior depended on whether I was at the end of the line. The following work well for me:

vmap <C-c> "py
nmap <C-c> "pyiw
vmap <C-p> "pp
nmap <C-p> "pP
imap <C-p> <Esc>"ppa

Content from tip 1387 (now removed; content to be merged here)Edit

Having replaced Notepad with gvim, these are my preferred editing shortcuts:

" Copy to 'clipboard registry'
vmap <C-c> "*y

" Select all text
nmap <C-a> ggVG


Have you seen vim70/mswin.vim, it comes with Vim 7.0 (and prior versions). It sets up a bunch of behavior that makes Vim work nice with Windows. Just source it in your vimrc. It's worth reading through for some ideas if you don't want to use the entire thing.

Content from tip 1528 (now removed; content to be merged here)Edit

Easy copy and paste in Vim:

" normal copy/paste
vmap <C-c> y<Esc>i
vmap <C-x> d<Esc>i
imap <C-v> <Esc>pi
imap <C-y> <Esc>ddi
map <C-z> <Esc>
imap <C-z> <Esc>ui

How it works:

Select something in visual mode. Then Ctrl-c (copy), Ctrl-x (cut).

After the operation you are in insert mode. So just navigate to the place where you want to paste and do Ctrl-v

When in insert mode Ctrl-y deletes the current line, Ctrl-z undo last change.

To make interaction with other applications more intuitive, see Easy_pasting_to_Windows_applications.


Need to state whether this is for a particular operating system. Does it work with the system clipboard? If not, is it useful?

See :help :behave for usage of mswin.vim. Most installs of Vim on Windows use mswin.vim. In that case, Ctrl-C, Ctrl-X, Ctrl-V, Ctrl-Z just behave as a Windows user would expect, and the tip as now written has no point.

If using gvim without mswin.vim (a good idea), look at the Edit menu for the recommended keys.

If wanting the mswin.vim key mappings, is there a reason to use this tip rather than mswin.vim?

Content from tip 866 (now removed; content to be merged here)Edit

"<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


What's wrong with the default? In Vim 7.1, see the files distributed with Vim:

  • vim/vim71/macmap.vim, vim/vim71/menu.vim, vim/vim71/mswin.vim
  • vim/vim71/autoload/paste.vim

Around Wikia's network

Random Wiki