151

我经常深入研究 apropos 和 docs 寻找类似以下内容的内容,只是为了放弃手头的任务:

(重复最后一个命令)

执行我刚刚执行的最后一个 C- 或 M- 命令(要反弹到 fn 键)

或者有时是相关的:

(描述最后一个功能)

我刚刚错误地发出了什么击键,我想将其效果添加到我的技巧包中。describe-key 很接近,但需要知道我输入了什么。

我只是对我可信赖的伙伴要求太多了吗?

4

10 回答 10

173

重复功能由repeat.elEmacs Lisp 包提供,它包含在标准 Emacs 发行版中。来自repeat.el的文档:

这个包定义了一个重复前面命令的命令,不管是什么,包括它的参数,不管它们是什么。此命令连接到键 Cx z。要重复上一个命令一次,请键入 Cx z。要立即重复第二次,只需键入 z。通过一次又一次地键入 z,您可以一遍又一遍地重复该命令。

要查看有关重复命令的其他信息,请C-h F repeat RET在 Emacs 中键入。

于 2008-11-09T12:12:15.393 回答
169

重复上一个命令

C-xz

一旦你按下它,只需 z 在那之后按下它就会重复(无需C-x再次按下)。

于 2008-11-09T13:18:54.773 回答
86

是的,有一个重复命令。它被称为repeat

  • 您可以使用 重复命令C-x z,然后点击z以继续重复。

有点震惊没人提repeat-complex-command,可从键位绑定C-x ESC ESC

于 2009-03-09T01:27:02.017 回答
64

关于“ describe-last-function ”:

有一个变量last-command设置为代表您所做的最后一件事的符号。所以这个 elisp 片段 - (describe-function last-command)- 应该为立即发生的事情提供文档。

describe-last-function所以你可以像这样做一个微不足道的工作

(defun describe-last-function() 
  (interactive) 
  (describe-function last-command))

将该 elisp 或等效项放入其中.emacs,您将拥有一个Mx describe-last-function

如果您在感兴趣的事情之后敲了几个键或做了一些修改 last-command 的事情,那么该command-history功能可能会令人感兴趣。您可以通过Mx 命令历史记录

于 2008-11-09T12:35:59.340 回答
24

此外,还会M-x view-lossage显示您输入的最后一百个(?)击键。因此,您将能够看到命令在哪里。这是我使用的,直到我现在才发现M-x command-history我认为我现在将使用它C-h w

于 2008-11-09T22:16:05.253 回答
18

我不太确定,但也许你正在寻找这个?

命令C-xz( repeat) 提供了另一种重复 Emacs 命令多次的方法。这个命令重复前面的 Emacs 命令,不管它是什么。重复一个命令使用之前使用的相同参数;它不会每次都读取新参数。

Emacs 手册,8.11 重复命令

于 2008-11-09T12:13:21.897 回答
9

可能这也有帮助......来自emacs帮助逐字:

C-x M-ESC runs the command repeat-complex-command
  which is an interactive compiled Lisp function in `simple.el'.
It is bound to <again>, <redo>, C-x M-:, C-x M-ESC.
(repeat-complex-command ARG)

Edit and re-evaluate last complex command, or ARGth from last.
A complex command is one which used the minibuffer.
The command is placed in the minibuffer as a Lisp form for editing.
The result is executed, repeating the command as changed.
If the command has been changed or is not the most recent previous command
it is added to the front of the command history.
You can use the minibuffer history commands M-n and M-p
to get different commands to edit and resubmit.
于 2009-11-14T00:53:34.587 回答
4

我个人发现塞巴斯蒂安的想法很有用。这是一个工作版本

(global-set-key "\C-r" #'(lambda () (interactive)
                                 (eval (car command-history))))
于 2011-11-12T16:45:01.297 回答
0

这是旧的,但是当我想要检索我在 Emacs 提示符下键入的最后一个命令时,Google 会首先弹出这个帖子。这些答案都不适合我,所以我决定为那些以后可能会像我一样偶然发现这个问题的人投入两分钱。我正在使用 Portacle,但我在这里找到了我想要的东西,所以我希望它足够通用,可以用于不同的设置。无论如何,对我有用的是使用C-↑C-↓循环历史。使用M-pM-n效果也很好,但我更喜欢使用箭头,因为我经常使用 Bash。

于 2019-05-29T14:47:22.013 回答
0

dot-mode是一种重复最后一个命令的方式。

从它的评论中:

It emulates the vi `redo' command, repeating the immediately preceding sequence of commands. This is done by recording input commands which change the buffer, i.e. not motion commands.

于 2020-11-04T00:35:50.027 回答