Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim copy-paste buffers

Tags:

vim

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?

like image 401
varnie Avatar asked Mar 06 '13 17:03

varnie


People also ask

Can you copy and paste in Vim?

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.

What is buffer Vim?

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.


2 Answers

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.

like image 88
Derek Avatar answered Oct 25 '22 14:10

Derek


Yes: You can use the blackhole buffer register: type "_dd

like image 41
Jan Avatar answered Oct 25 '22 14:10

Jan