如何添加行到一个 vim 寄存器,而不覆盖它

我想在寄存器中猛拉一行: "{register}y,但不覆盖以前在寄存器中的内容。我经常需要复制寄存器中的非连续行,有时我喜欢像堆栈一样使用寄存器。

例如:

line1
line2
line3

我想复制 line1,把光标放在上面,然后输入 "ay,然后转到 line3,做 "ay。然后,当我将做 "ap,两个 line1line3都将被粘贴。

没有插件这可能吗? 有插件吗?

17648 次浏览

If you want to append to a named register use it's corresponding upper case character. i.e. In your example:

"ayy
"Ayy
"ap

Just to expand on MarkB's response, did you know you can also use markers to select a block of text for your yank?

Go to the first line of the block you want to yank and enter the mark command after selecting a letter as the marker, e.g.

ma  (entered in command mode, i.e. no colon)

then go to the bottom of the block you want to yank and enter the command:

:'a,.ya A

this command means take the block of text from the line containing my marker called a up to the current line and yank it into buffer a. Same rules as MarkB mentioned apply, use lowercase buffer name to overwrite the buffer. Use uppercase buffer name to append to the buffer. So in this case this will append to the contents of buffer a.

N.B. The 'a' used for your marker has nothing to do with the 'a' used to select your register. (AFAIK but YMMV)

BTW 'a (apostrophe a) refers to the line containing the marker a. `a (backquote a) refers to the character under the cursor when you entered ma.

d`a (also entered in command mode)

is useful because it will delete the text between the character marked with marker a up to the character just before the character where you cursor is currently located.