Suppose I have the following text (I have numbered the lines for clarity) and the cursor is at the beginning of the 5th line:
1
2 var x = 1;
3 var y = 2;
4
5 if (true) {
6 print("Hey!");
7 }
Okay, now I try to cut the lines 5, 6, 7 (all that "if" thingy). For that purpose I do:
Vjjd
. Now it appears I am at the beginning of the 4th line which is an empty string.
My question: is it possible at this moment to remove the 4th line without loosing previously copied lines 5, 6, 7 (that "if" thingy), so that I'll be able to paste them somewhere else, say, on the 1st line later?
You can use a movement command or up, down, right, and left arrow keys. Press y to copy, or d to cut the selection. Move the cursor to the location where you want to paste the contents. Press P to paste the contents before the cursor, or p to paste it after the cursor.
Buffers in vim are the in-memory text of files. Your window is a viewport on a buffer. You can switch between open buffers, this is similar to tabs in other editors. Vim does have a concept of tabs too, but they are slightly different, read more about tabs in the Windows section.
You can always yank or delete into a register using "n, where n is just about any key. See a list of available registers in "help registers", some of which have special meaning. For example, you could do:
> "a3dd (to delete the last three lines into a register called a)
> dd (to delete the blank line)
> "ap (to paste the a register)
You can also use Vjj"ad, to match what you were doing in the original question.
Yes: You can use the blackhole buffer register: type "_dd
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