title: Copy and Paste
Copying and Pasting in Vim
In Vim, copying is commonly referred to as ‘yanking’, and pasting remains the same.
The keys used for yanking and pasting in Vim are:
xto delete a character
pto put/paste after cursor
Pto put/paste before cursor
ppto put/past a whole line
ddto cut a whole line
"to cut or yank to a register
To yank or cut, type
d, followed by a ‘text object’. These describe how much text should be yanked or deleted. For example,
yw copies one word and
d$ deletes from the cursor to the end of the line. They can also both be used in visual mode, pressing
v and moving the cursor and then pressing
d deletes all text inside of the selection.
A register is just another name for clipboard. But unlike other text editors, Vim has many of such “clipboards”.
To yank or delete to a register, type
"<register name><command> (e.g.:
"ayw to [y]ank [w]ord to register
a). Register names can be only one character long for obvious reasons (
"3 are allowed, but
"MyRegisterName are not). The default register that is stored to when no register is specified is
" and the system clipboard that can be accessed in other programs is
+. You can also use lower case characters to access registers and use uppercase characters to append to registers. For example
"dyy copies the current line to the
d register, typing
"D3yw copies the next 3 words and adds them to what is already stored in
Pasting can be done in normal mode or in insert mode.
In normal mode:
ppastes after the cursor
Ppastes before the cursor
gppastes after the cursor and moves the cursor to the end of the paste
gPpastes before the cursor and moves the cursor to the end of the paste
In insert mode type
Ctrl-r to paste and then type a register, normally
", this will paste from that register where the cursor is and move the cursor to after the paste.