Emacs: Repeat Last Command
Here are 2 useful commands to repeat last command.
repeat
repeat-complex-command
Repeat Last Command
- Alt+x
repeat
【Ctrl+x z】 - repeat the last command.
Once you called repeat
, you can call it again by pressing or holding down the last key used for invoking repeat
.
That means, for any command that does not have a shortcut (or if the shortcut is difficult to press), now you can repeat it by simply holding down a key.
For example,
try
Alt+x forward-word
,
now
Ctrl+x z z z.
It'll do it 3 times.
This is especially useful to repeat
call-last-kbd-macro
[see Emacs: Keyboard Macro]
.
Major mode commands usually have keys such as
Ctrl+c Ctrl+key
that is hard to repeat.
So the repeat
command is super useful.
Repeat Last Complex Command
- Alt+x
repeat-complex-command
【Ctrl+x Alt+:】 - Repeat the last command that has prompts.
Tip: repeat-complex-command
is great for:
- Repeating a command without answering the prompts again.
- Get the actual emacs lisp code. Copy paste it elsewhere, edit and eval.
- Converting emacs Regular Expression from interactive form to lisp string form with all proper backslash escape added. [see Emacs Lisp: Convert Regex to Lisp Regex String]
example of repeat-complex-command
- Alt+x
list-matching-lines
and type the search text (e.g. cat). [see Emacs: Find Replace in Current File] - Alt+x
repeat-complex-command
. You get(list-matching-lines "cat" nil)
. Press enter to repeat it, or, copy the code and paste in another buffer. you can edit it, and eval it byeval-last-sexp
[see Emacs: Evaluate Elisp Code]
List Command History
- Alt+x
list-command-history
-
list all recent commands called involving the
Minibuffer.
emacs 29 list-command-history 2023-09-08