vim剪切和粘贴历史


60

当我在vim中“剪切”时,我相信有些寄存器记录了我最近剪切过的所有事情的历史。如何访问这些寄存器?

例如,假设我连续切出这些单词中的每一个

  • '你好'
  • '世界'
  • '和'
  • 'Vim'

请注意,我实际上并没有将这些编辑保存到特定的寄存器中,我只是连续四次使用'd'。

Answers:


102

:帮助注册

命令显示有10个编号的寄存器("0"9)。

登记"0是最近被拉扯的东西; register "1具有最近删除的文本,register "2先前的删除,"3之前具有的删除,依此类推。

如果删除各行依次寄存器"1"2"3"4将含有“Vim的”,“和”,“世界”和“你好”,分别。

您可以使用:reg(或:registers)命令对此进行验证:

:reg
""   Vim^J
"1   Vim^J
"2   And^J
"3   World^J
"4   Hello^J

因此,一次删除四行后,您可以恢复第二行(“世界”)

"3p

因为它是第三次删除。


太棒了; 但是,我想要最新的“被拖拉”文本吗?
Alexey 2010年

因此,您将使用:p(与“ 0p”相同)
njd 2010年

1
在阅读时,还要注意特殊的寄存器,尤其是“ *”和“ +” :help registers非常有用
丹尼尔·安德森

3
上帝,您每天都会学到一些新知识。这很棒。谢谢,@ njd。
ELLIOTTCABLE

3
这个答案遗漏了一个重要的细节:这样,历史记录中仅存储一行或多行的删除。如果按照问题中描述的OP的方式删除单词(使用d4次,而不是dd),则除最后一个删除的单词之外的所有单词都将丢失。
亚历山大·雷希施泰纳

8

除了njd的答案外,还可以使用YankRing插件简化此操作。除了使浏览先前的yanks更容易之外,您还可以配置一些键以允许将先前的yanks弹出“堆栈”。这使您可以执行以下操作:

yy    " Copy first line
yy    " Copy second line
yy    " Copy third line
yy    " Copy fourth line
" Assumes you've mapped ,p to be the pop command: choose your preferred key or key-combination
,p    " Paste fourth line and pop it off the Yank Ring
,p    " Paste third line and pop it off the Yank Ring
,p    " Paste second line and pop it off the Yank Ring
,p    " Paste first line and pop it off the Yank Ring

4
您能否添加如何映射,p以弹出上一个洋基?
安德鲁·伍德
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.