这篇文章说“Emacs有重做,因为你可以在撤销的时候反转方向,从而撤销撤销”。

这是什么意思?用户如何使用Emacs“重做”?


当前回答

对于那些想要拥有更常见的撤消/重做功能的人,有人编写了undo-tree.el。它提供了非emacs撤消的外观和感觉,但提供了对撤消历史的整个“树”的访问。

我喜欢Emacs的内置撤销系统,但发现这个包非常直观。

以下是该文件本身的评论:

Emacs has a powerful undo system. Unlike the standard undo/redo system in most software, it allows you to recover any past state of a buffer (whereas the standard undo/redo system can lose past states as soon as you redo). However, this power comes at a price: many people find Emacs' undo system confusing and difficult to use, spawning a number of packages that replace it with the less powerful but more intuitive undo/redo system. Both the loss of data with standard undo/redo, and the confusion of Emacs' undo, stem from trying to treat undo history as a linear sequence of changes. It's not. The `undo-tree-mode' provided by this package replaces Emacs' undo system with a system that treats undo history as what it is: a branching tree of changes. This simple idea allows the more intuitive behaviour of the standard undo/redo system to be combined with the power of never losing any history. An added side bonus is that undo history can in some cases be stored more efficiently, allowing more changes to accumulate before Emacs starts discarding history.

其他回答

对于那些想要拥有更常见的撤消/重做功能的人,有人编写了undo-tree.el。它提供了非emacs撤消的外观和感觉,但提供了对撤消历史的整个“树”的访问。

我喜欢Emacs的内置撤销系统,但发现这个包非常直观。

以下是该文件本身的评论:

Emacs has a powerful undo system. Unlike the standard undo/redo system in most software, it allows you to recover any past state of a buffer (whereas the standard undo/redo system can lose past states as soon as you redo). However, this power comes at a price: many people find Emacs' undo system confusing and difficult to use, spawning a number of packages that replace it with the less powerful but more intuitive undo/redo system. Both the loss of data with standard undo/redo, and the confusion of Emacs' undo, stem from trying to treat undo history as a linear sequence of changes. It's not. The `undo-tree-mode' provided by this package replaces Emacs' undo system with a system that treats undo history as what it is: a branching tree of changes. This simple idea allows the more intuitive behaviour of the standard undo/redo system to be combined with the power of never losing any history. An added side bonus is that undo history can in some cases be stored more efficiently, allowing more changes to accumulate before Emacs starts discarding history.

默认情况下,Emacs中的重做需要按C-g,然后撤销。

但是也可以使用Emacs内置的undo来实现重做命令。

undo-fu包使用Emacs内置的撤销功能来公开撤销和重做。


编辑,撤销fu现在已经集成到邪恶模式(如果你是一个邪恶模式的用户)。

例子:

(use-package undo-fu)
(use-package evil
  :init
  (setq evil-undo-system 'undo-fu))

小心重做时的撤销树怪癖!

许多流行的“入门套件”(prelude, purcell, spacemacs)都捆绑了撤销树。大多数(全部?)甚至自动启用它。如前所述,撤销树是可视化和遍历撤销/重做树的方便方法。前奏甚至给了它一个关键和弦(uu),还有c - xu。

问题是:undo-tree似乎破坏了Emacs默认的和众所周知的重做绑定:C-g C-/。

相反,你可以使用这些对称键来撤销/重做:

C-/     undo
C-S-/   redo

这些是有用的,因为有时你想快速重做而不打开可视化工具。

Doom Emacs用户,我希望你已经滚动到这里或在页面上搜索“Doom”了……

毁灭Emacs打破了香草Emacs重做快捷方式: C-g C-/ C-/ C-/ etc(或C-g C-_ C-_ C-_ etc) ...相反,它一直在撤销。 Doom Emacs也打破了撤销树重做快捷方式,在其他答案中提到,这对spacemacs等很有用: S-c -/(又名c -?) ...而不是抛出错误“C-?”没有定义”。

你需要的是:

处于邪恶模式(C-z切换进入和退出邪恶模式)(在邪恶模式应该看到蓝色光标,而不是橙色光标)和 进入“命令模式”,也就是“正常模式”(而不是“插入模式”)(Esc切换到命令模式)(应该看到块光标,而不是行光标),然后是 U代表撤销 重做的C-r

简短的版本:通过撤消撤消。如果撤消,然后执行一个非编辑命令,如C-f,那么下一次撤消将撤消撤消,导致重做。

长版:

您可以将撤消看作是对操作堆栈的操作。如果在一系列撤销操作之后执行某些命令(甚至是C-f之类的导航命令),则所有的撤销操作都将被推入操作堆栈。因此,下一个undo命令将撤销上一个命令。假设你确实有一个这样的操作序列:

插入“foo” 插入“酒吧” 我喜欢垃圾邮件。

现在,撤销。它将撤销最后一个操作,结果是以下列表:

插入“foo” 插入“酒吧”

如果你在这一点上做了一些除了撤销之外的事情——比如C-f,操作堆栈看起来像这样:

插入“foo” 插入“酒吧” 我喜欢垃圾邮件。 撤销插入“我爱垃圾邮件”

当你撤消时,首先要撤消的是撤消。导致您的原始堆栈(和文档状态):

插入“foo” 插入“酒吧” 我喜欢垃圾邮件。

如果您执行一个修改命令来打破undo序列,则该命令被添加在undo之后,因此是之后要撤消的第一件事。假设你在bar上倒空,而不是在C-f上。那么你就有了

插入“foo” 插入“酒吧” 我喜欢垃圾邮件。 撤销插入“我爱垃圾邮件” 删除“酒吧”

这种添加/重新添加会无限地发生。它需要一点时间来适应,但它确实为Emacs提供了高度灵活和强大的撤消/重做机制。