To go back to normal mode from any other mode, just press the Esc key. Vim has its own terminology for copying, cutting, and pasting. Copy is called yank ( y ), cut is called delete ( d ), and paste is called put ( p ).
The vi command-mode equivalent of "copy and paste" is yank and put; the equivalent of "cut and paste" is delete and put. The methods for copying or moving small blocks of text in vi involves using a combination of the yank , delete , and put commands.
Deleting Multiple LinesPress the Esc key to go to normal mode. Place the cursor on the first line you want to delete. Type 5dd and hit Enter to delete the next five lines.
Pass to the _
register, the black hole.
To delete a line without sticking it in the registers:
"_dd
See also :help registers
.
It's probably safest, if you want to paste something over and over again, to yank it into a "named" register.
"aY
Yanks a line into the a
register. Paste it with "ap
.
Your yanked line should still be in the register 0. So do
"0p
to paste the line (and delete whenever you want)
All yank and delete operations write to the unnamed register by default. However, the most recent yank and most recent delete are always stored (separately) in the numbered registers. The register 0
holds the most recent yank. The registers 1-9
hold the 9 most recent deletes (with 1
being the most recent).
In other words, a delete overwrites the most recent yank in the unnamed register, but it's still there in the 0
register. The blackhole-register trick ("_dd
) mentioned in the other answers works because it prevents overwriting the unnamed register, but it's not necessary.
You reference a register using double quotes, so pasting the most recently yanked text can be done like this:
"0p
This is an excellent reference:
another possibility is:
yank your lines like you would do normally
go to where you want to paste them, enter visual line mode (V
)
select the lines you want to replace
hit p
to paste your lines.
this also has the added benefit, that the buffer is "swapped" with the replaced contents
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With