您如何“重做”? “撤消”后发生的变化用 Emacs 吗?
这篇文章说“Emacs 具有重做功能,因为您可以撤消时反转方向,从而撤消撤消”。
这意味着什么?用户如何使用 Emacs 进行“重做”?
This article says that "Emacs has redo because you can reverse direction while undoing, thereby undoing the undo".
What does this mean? How can a user 'redo' with Emacs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
如果要重做上次操作,请执行以下操作。
ESC
C + /
)If you want to redo the last operation, do the following.
ESC
C + /
)在厄运 emacs 中,
Ctrl + Shift + -
撤消Alt + Shift + -
重做In doom emacs,
Ctrl + Shift + -
to undoAlt + Shift + -
to redo简短版本:通过撤消撤消。如果您撤消,然后执行非编辑命令,例如 Cf,则下一个撤消将撤消该撤消,从而导致重做。
更长的版本:
您可以将撤消视为对操作堆栈进行操作。如果您在一系列撤消操作后执行某些命令(甚至是导航命令,例如 Cf),则所有撤消都会被推送到操作堆栈。因此,下一个撤消操作将撤消上一个命令。假设您确实有一个如下所示的操作序列:
现在,您可以撤消。它撤消最后一个操作,产生以下列表:
如果此时执行撤消以外的其他操作 - 例如 Cf,操作堆栈如下所示:
现在,当您撤消时,首先撤消的就是撤消。产生原始堆栈(和文档状态):
如果您执行修改命令来破坏撤消序列,则该命令将在撤消之后添加,因此是第一件事之后将被撤销。假设您在“bar”上退格而不是按 Cf。然后你就会
这种添加/重新添加会无限地发生。这需要一些时间来适应,但它确实为 Emacs 提供了高度灵活且强大的撤消/重做机制。
Short version: by undoing the undo. If you undo, and then do a non-editing command such as C-f, then the next undo will undo the undo, resulting in a redo.
Longer version:
You can think of undo as operating on a stack of operations. If you perform some command (even a navigation command such as C-f) after a sequence of undo operations, all the undos are pushed on to the operation stack. So the next undo undoes the last command. Suppose you do have an operation sequence that looks like this:
Now, you undo. It undoes the last action, resulting in the following list:
If you do something other than undo at this point - say, C-f, the operation stack looks like this:
Now, when you undo, the first thing that is undone is the undo. Resulting in your original stack (and document state):
If you do a modifying command to break the undo sequence, that command is added after the undo and is thus the first thing to be undone afterwards. Suppose you backspaced over "bar" instead of hitting C-f. Then you would have had
This adding/re-adding happens ad infinitum. It takes a little getting used to, but it really does give Emacs a highly flexible and powerful undo/redo mechanism.
撤消: C-_
撤消后重做: Cg C-_
在 C-_ 重做 C-_ 撤消的操作
要多次重做 emacs 命令,请执行命令,然后键入 Cxz,然后在 z 键上多次键入以重复该命令(有趣)当你想多次执行一个宏时)
To undo: C-_
To redo after a undo: C-g C-_
Type multiple times on C-_ to redo what have been undone by C-_
To redo an emacs command multiple times, execute your command then type C-xz and then type many times on z key to repeat the command (interesting when you want to execute multiple times a macro)
C-/
C-/
C-/
Cg
C-/
Cg
C-/
C-/
。请注意,Cg
不重复。Cg
C-/
Cg
C-/
C-/
如果您按下了任何键(无论是键入字符还是只是移动光标)自上次撤消命令以来,无需在下一次撤消/重做之前键入
Cg
。Cg
只是一个安全的按键,它本身没有任何作用,但可以作为非撤消键来表示撤消序列的结束。按另一个命令,例如Cf
也可以;只是它会将光标从您所在的位置移动。如果您无意中按了
Cg
或其他命令,并且现在正在以错误的方向撤消操作,只需按Cg
即可再次反转方向。在达到您想要的撤消之前,您必须一路撤消意外的重做和撤消,但如果您继续按C-/
,您最终将达到您想要的状态。事实上,如果您按一下Cg
一次,然后按C-/
足够多次,缓冲区曾经处于的每个状态都是可以访问的。除了
C-/
之外,撤消
的替代快捷键还有C-_
、Cx u
和>Mx
撤消
。有关 Emacs 撤消系统的更多详细信息,请参阅 Emacs 手册中的撤消。
C-/
C-/
C-/
C-g
C-/
C-g
C-/
C-/
. Note thatC-g
is not repeated.C-g
C-/
C-g
C-/
C-/
If you have pressed any keys (whether typing characters or just moving the cursor) since your last undo command, there is no need to type
C-g
before your next undo/redo.C-g
is just a safe key to hit that does nothing on its own, but counts as a non-undo key to signal the end of your undo sequence. Pressing another command such asC-f
would work too; it’s just that it would move the cursor from where you had it.If you hit
C-g
or another command when you didn’t mean to, and you are now undoing in the wrong direction, simply hitC-g
to reverse your direction again. You will have to undo all the way through your accidental redos and undos before you get to the undos you want, but if you just keep hittingC-/
, you will eventually reach the state you want. In fact, every state the buffer has ever been in is reachable, if you hitC-g
once and then pressC-/
enough times.Alternative shortcuts for
undo
, other thanC-/
, areC-_
,C-x u
, andM-x
undo
.See Undo in the Emacs Manual for more details on Emacs’s undo system.
对于那些想要拥有更常见的撤消/重做功能的人,有人编写了 <代码>undo-tree.el。它提供非 Emacs 撤消的外观和感觉,但提供对撤消历史记录的整个“树”的访问。
我喜欢 Emacs 的内置撤消系统,但发现这个包非常直观。
以下是文件本身的评论:
For those wanting to have the more common undo/redo functionality, someone has written
undo-tree.el
. It provides the look and feel of non-Emacs undo, but provides access to the entire 'tree' of undo history.I like Emacs' built-in undo system, but find this package to be very intuitive.
Here's the commentary from the file itself:
请注意撤消树重做的怪癖!
许多流行的“入门工具包”(prelude、purcell、spacemacs)都与撤消树捆绑在一起。大多数(全部?)甚至自动启用它。如前所述,撤消树是可视化和遍历撤消/重做树的便捷方法。 Prelude 甚至给它一个调和弦 (
uu
),还有Cx u
。问题是:undo-tree 似乎破坏了 Emacs 的默认且众所周知的重做绑定:
Cg C-/
。相反,您可以使用这些对称键进行撤消/重做:
这些键很有用,因为有时您希望在不打开可视化工具的情况下快速重做。
Beware of an undo-tree quirk for redo!
Many popular “starter kits” (prelude, purcell, spacemacs) come bundled with undo-tree. Most (all?) even auto-enable it. As mentioned, undo-tree is a handy way to visualize and traverse the undo/redo tree. Prelude even gives it a key-chord (
uu
), and alsoC-x u
.The problem is: undo-tree seems to wreck Emacs’ default and well-known binding for redo:
C-g C-/
.Instead, you can use these symmetrical keys for undo/redo:
These are useful since sometimes you want to quickly redo without opening up the visualizer.
Emacs 28 添加了一个 redo 命令(称为 <代码>撤消重做)。
如果您想要更典型的撤消/重做,可以使用以下命令。
要访问此功能(也可以使用非线性历史记录,请参阅 undo-fu 这是 emacs 上内置 undo 的薄包装器)。
Emacs 28 adds a redo command (called
undo-redo
).If you want to have more typical undo/redo, the following commands can be used.
To access this functionality (with the ability to use non-linear history too, see undo-fu which is a thin wrapper on emacs built in undo).
我发现
redo.el
对于“正常”操作非常方便撤消/重做,我通常将其绑定到 CSz 并将撤消绑定到 Cz,如下所示:只需下载文件,将其放入您的 lisp 路径中并将以上内容粘贴到您的
.emacs
中。I find
redo.el
extremly handy for doing "normal" undo/redo, and I usually bind it to C-S-z and undo to C-z, like this:Just download the file, put it in your lisp-path and paste the above in your
.emacs
.默认情况下,Emacs 中的重做需要按 Cg,然后撤消。
然而,也可以使用 Emacs 内置的 undo 来实现重做命令。
包undo-fu,使用Emacs内置的撤消功能来公开撤消和重做。
编辑,撤消功能现在已集成到邪恶模式中(如果您是邪恶模式用户)。
例子:
By default, redo in Emacs requires pressing C-g, then undo.
However it's possible use Emacs built-in undo to implement a redo command too.
The package undo-fu, uses Emacs built-in undo functionality to expose both undo and redo.
Edit, undo-fu has now been integrated into evil-mode (if you're an evil-mode user).
Example:
Doom Emacs 用户,我希望您已经滚动到这里或在页面上搜索“doom”...
Cg
C-/
C-/
C-/
等(或Cg
<代码>C-_C-_
C-_
等)...相反,只是不断地破坏。
SC-/
(又名C-?
)...相反,这会引发错误“C-?未定义”。
你需要的是:
Cz
切换进入和退出邪恶模式)(在邪恶模式下应该看到蓝色光标,而不是橙色光标)并且Esc
切换到命令模式)(应该看到块光标,而不是行光标),然后是u
表示撤消,Cr
表示重做Doom Emacs users, I hope you've scrolled this far or searched for 'doom' on the page...
C-g
C-/
C-/
C-/
etc (orC-g
C-_
C-_
C-_
etc)...and instead that just keeps undoing.
S-C-/
(AKAC-?
)...and instead that throws the error "C-? is not defined".
What you need is:
C-z
to toggle in and out of evil-mode) (in evil-mode should see blue cursor, not orange cursor) andEsc
to switch to command mode) (should see block cursor, not line cursor), and then it'su
for undo andC-r
for redo