Vim 中如何使用撤消树?
Vim 的撤消/重做系统是无与伦比的。 输入一些内容,撤消,输入其他内容,您仍然可以返回您输入的第一个内容,因为 Vim 使用撤消树而不是堆栈。 在几乎所有其他程序中,您输入的第一条内容的历史记录都会在这种情况下丢失。
这是我第一次听说这个。 如何沿着树原路返回?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
另请参见
:h undo-redo
,其中列出了所有命令及其用法。有两种方法可以遍历撤销树。 一是“回到过去”。
g+
和g-
将以时间顺序或逆时间顺序遍历树中的所有节点(这可能有点令人困惑,因为它可以在撤消分支之间任意跳转,但如果你做g-
足够长的时间,你最终总会到达你需要去的地方)。:earlier
和:later
采用时间描述符,例如7m
或1h
; 同样,这可以让你在撤消分支之间任意跳转。另一种方法是使用
:undo n
跳转到树中的特定节点,其中n
是操作的编号。 (所有操作,即文本添加、删除、替换,都会在您执行这些操作时按顺序编号。)您可以通过:undolist
查找撤消树的叶子上的操作编号。 这将使您轻松地在分支之间跳转。 然后,您可以使用u
和Ctrl-R
在该分支上上下移动。Vim 帮助中有一些很好的例子。 弄清楚它是如何工作的最好方法就是尝试一下。
See also
:h undo-redo
, which lists all the commands and their usage.There are two ways to traverse the undo tree. One is to go "back in time".
g+
andg-
will traverse all of the nodes in the tree in chronological or reverse-chronological order (which can be a bit confusing, because it can jump arbitrarily between undo branches, but if you dog-
long enough you'll always get where you need to go eventually).:earlier
and:later
take a time descriptor like7m
or1h
; again this can jump you arbitrarily between undo branches.The other way is to jump to specific nodes in the tree using
:undo n
wheren
is a number of an action. (All actions, i.e. text additions, deletions, replacements, are numbered sequentially as you do them.) You can look up the number of the actions on the leaves of the undo tree via:undolist
. This will let you jump between branches easily. You can then useu
andCtrl-R
to move up and down that branch.There are some good examples in the Vim help. The best way to figure out how this works is to play with it a bit.
我为 Vim 编写了一个撤消树可视化插件:
https://github.com/sjl/gundo.vim
我个人发现绘制树图就像这是我能理解它的唯一方法。
I wrote an undo tree visualization plugin for Vim:
https://github.com/sjl/gundo.vim
Personally I found that graphing the tree like this was the only way I could make sense of it.
本页解释了您需要了解的所有内容:
http://vimdoc.sourceforge.net/htmldoc/usr_32。 html
This page explains everything you need to know:
http://vimdoc.sourceforge.net/htmldoc/usr_32.html
如果您使用的是 vim,则可以使用以下方式浏览撤消树:
u
:(撤消)在撤消树中向后移动Ctrl+R
:(重做)向前移动在撤消树中将文档时间向后或向前移动的其他方法:
:earlier 15m
: 向后移动 15 分钟:later 15m
: 向前移动 15 分钟If you're using vim, you can navigate through the undo tree using:
u
: (undo) move back in the undo treeCtrl+R
: (redo) move forward in the undo treeOther ways of bringing document back or forward in time:
:earlier 15m
: move back in time 15 minutes:later 15m
: move front in time 15 minutes我知道这个问题已经得到解答,但我想我应该添加一个例子。
创建一个新文件并输入:
undol
将显示撤消树。 此时您还没有撤消任何操作,请按 ESC 并将该行修改为:
切换到正常模式并按 u(撤消),这应该删除“旧”。 如果您选中
undol
,此时您仍然只有一个分支。现在修改该行,使其显示:
现在
:undol
显示:您可以通过键入此命令切换到第一个分支,
这会将您移动到与数字 2 关联的分支的末尾。您可以沿着该分支移动与
g+
和g-
。 此时,g+
将不会执行任何操作(您位于叶子位置)。 如果您按g-
,“old”将被删除(您正在遍历第一个撤消树)。也就是说,如果您使用g-
删除“old”并按g+,“旧”将被重做。
如果您输入
You 将跳转到第二个撤消分支的叶子,它将显示:
I'm aware this question has been answered, but I thought I'd add an example.
Create a new file and type:
undol
will display the undo tree. At this point you haven't undone anythingnow press ESC and modify the line to:
switch to normal mode and press u (undo), this should remove "old". If you check
undol
, at this point you still have only one branch.now modify the line so it says:
Now
:undol
shows:You can switch to the first branch by typing
this will move you to the end of the branch associated with number 2. You can move along this branch with
g+
andg-
. At this pointg+
will do nothing (you are at the leaf). If you pressg-
“old" will be removed (you are traversing the first undo tree). That is if you remove “old” withg-
and pressg+
again, “old" will be redone.If you type
You will jump to the leaf of the second undo branch and it will read:
这里总结了很多内容:
http://vim.wikia.com/wiki/Using_undo_branches
A lot of this is summed up here:
http://vim.wikia.com/wiki/Using_undo_branches
包 undotree 是用纯 vim 脚本编写的,因此没有要求。
并在为时已晚之前将其添加到您的 vimrc 中:
The package undotree is written in pure vimscript so no requirement.
And add this to your vimrc before it is too late:
除了使用gundo.vim之外,我还喜欢提到
g+
和g-
Besides using gundo.vim I like to mention
g+
andg-