问题描述
这个问题可能之前已经回答过,但是我尝试搜索,但是找不到任何地方的答案.
This question was probably answered before, but I tried searching and could not find the answer anywhere.
我对Vim有点陌生,遇到以下问题.一旦我拉出一条线并将其粘贴,就无法再次粘贴.例如,说在Word环境中,您将复制一个文本,将其粘贴,然后可以再次将其粘贴.但是在Vim中,一旦我将其粘贴然后尝试再次粘贴(p),它就会将我粘贴了蓝线的文本粘贴到上面.
I am somewhat new to Vim and I am having the following issue. Once I yank a line and paste it, i cannot paste it again. For example, say in Word environment you would copy a text, paste it and then you can paste it again further. But in Vim, once I have pasted it and then try pasting again (p), it pastes the text I pasted the yanked line over.
因此,例如,我将此行被选中"行拖到了我不希望此行"上,因此此行被选中了"发生在我不希望此行"之上.如果再次单击p,将不会粘贴此行已被猛拉",但会显示我不希望此行".
So for example, I yanked the line "This line is yanked" onto "I don't want this line" and so "This line is yanked" takes place over "I don't want this line".If I click p further on again, I won't get "This line is yanked" pasted but will get "I don't want this line".
有没有办法我可以再次粘贴同一条被拉线的线而又不回去再次拉动它呢?
Is there a way I can paste the same yanked line over again without going back and yanking it again?
推荐答案
这是由于vim的寄存器.当您在另一行上粘贴一条拉线的行时,刚删除(通过粘贴)的行将在默认寄存器(存储拉线的行)中占据拉线的位置.这是为了使切换线变得容易.拉一个,粘贴在另一个上,然后返回并再次粘贴.但是,要保留被拖拽的行,可以指定一个寄存器,因此可以使用"ay
代替使用y
,这会将您的行拖到寄存器a
中.现在要粘贴,您可以使用"ap
,这将粘贴寄存器a
的内容,该内容不会被覆盖.
This is because of vim's registers. When you paste a yanked line over another line, the line you just deleted (by pasting over it) takes up the place of the yanked line in the default register (which stores yanked lines). This is to make switching lines easy. Yank one, paste over the other and go back and paste again. However, to keep your yanked line you can specify a register, so instead of using y
you can use "ay
and this will yank your line into register a
. Now to paste you can use "ap
and this will paste the contents of register a
, which will not get overwritten.
如果在vim中启用了(在大多数系统上也是如此),则从系统剪贴板(其他应用程序的复制粘贴)中粘贴"+y
或"*y
和"+p
或"*p
作为奖励.
As a bonus "+y
or "*y
and "+p
or "*p
paste from the system clipboard (other applications' copy paste) if it is enabled in vim (which it is on most systems).
如注释中所述,当您使用yank命令时,带阴影的文本不仅会进入默认寄存器,还会进入0寄存器(当您粘贴其他内容时不会被覆盖).这意味着您通常可以使用y
拉动,然后使用"0p
粘贴,并且粘贴的内容不会覆盖它.
As mentioned in the comments, when you use the yank command, the yanked text not only goes into the default register but also to the 0 register (which won't get overwritten when you paste over something else). This means that you can normally yank using y
and then paste it with "0p
and it won't get overwritten by anything you paste over.
这篇关于在Vim中粘贴了拉线之后,为什么不能再次粘贴呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!