问题描述
我该如何撤消对缓冲区的所有更改(从打开缓冲区的那一刻开始)?我想可能会有某种:earlier
命令执行此操作。
How can I undo all the changes made to a buffer starting with the moment it was opened? I imagine there may be some form of the :earlier
command that does this.
更新:许多建议使用遍历到较早文件写入的解决方案。这不是我要的我希望恢复到最初将文件加载到缓冲区时的文件原始状态,无论从那以后进行了多少写操作。
UPDATE: Many are suggesting solutions for traversing to earlier file writes. This isn’t what I asked for. I want to return to the original state the file was in when I originally loaded it into a buffer, no matter how many writes were made since then.
推荐答案
将当前缓冲区恢复到Vim撤消列表中记录的第一个
更改之前的状态(请参见:help undo-tree ),我们
可以使用:undo
命令的两个连续调用:
To revert the current buffer to the state prior to the very firstchange recorded in the Vim undo list (see
:help undo-tree
), wecan use two consecutive invocations of the :undo
command:
:u1|u
第一个命令(
:undo 1
)在第一个已注册的更改
之后恢复到缓冲区的状态,而第二个命令(:undo
)
会自动还原第一个更改。
The first command (
:undo 1
) reverts to the state of the buffer afterthe very first registered change, while the second command (:undo
)reverts that first change itself.
从8.1版开始(请参见
:helpg补丁8.0.1441
),Vim允许$ b $ b传递更改数字0作为:undo
命令的参数
在进行任何已更改之前引用状态,从而使
可以达到相同的效果一次调用即可完成:
Starting with version 8.1 (see
:helpg Patch 8.0.1441
), Vim allowsto pass the change number 0 as an argument to the :undo
commandto refer to the state before any registered changes, thus makingit possible to achieve the same effect in a single invocation:
:u0
这篇关于自从Vim打开缓冲区以来,如何撤消缓冲区中的所有更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!