Vim/Copy Cut and Paste
From Debuntu
< Vim
Contents |
Basic Copy/Cut and Paste
Copying
Copying is done via the Y key. Vi uses the term yank (thus y key)
In ecape mode:
| Command | Action |
|---|---|
| Y or yy | copies the current line |
| [count]Y | copies [count] line from the current line |
| [range]y | copies a range of line |
| :0,.y | copies line from the beginning of line until current cursor (not included) |
| yG | copies line from the current line to end of file |
| y$ | copies from the current cursor to end of line |
| y0 | copies from the beginning of line until current cursor (not included) |
| yw | copies from current position till end of the word |
Cutting
By typing D/d instead Y/y you will cut the text and be able to paste it later.
Pasting
Once you have copied/deleted some text you can paste it with:
In ecape mode:
| Command | Action |
|---|---|
| P | paste text before the cursor |
| p | paste text after the cursor |
| gP | Same than P but leave the cursor just after the new text |
| gp | Same than p but leave the cursor just after the new text |
| :[line]pu | paste the text just after line number |
| :[line]pu! | paste the text just before line number |
Advance Copy/Cut Paste
Using Multiple buffer
You can define multiple buffers to save the text you copied/cut
In non-range mode, you need to use:
"x
where x is the name of the buffer (AKA register) before the command.
In range mode, the syntax is as follow:
:[range]y x
So, for instance copying line 1 to 3 into buffer f:
:1,3y f
and paste it after line 5 with:
:5pu f
or paste if at current cursor with:
"f P