Emacs: Repeat Last Command
Here are 2 useful commands to repeat last command.
repeatrepeat-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: Key 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 prompted for user to answer questions but without prompting again.
💡 TIP:
repeat-complex-commandis 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 Elisp: Convert Regex to Lisp Regex String〕
Example of repeat-complex-command
- Alt+x
list-matching-linesand type the search text (e.g. cat). 〔see Emacs: Find Replace〕 - 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
Emacs Principle
- Emacs: Principle, Command, Keys
- Emacs: Jargons (Glossary)
- Emacs: Mode Line (Status Bar)
- Emacs: Major Mode
- Emacs: Minor Mode
- Emacs Init: Hook
- Emacs: Minibuffer
- Emacs: Messages Buffer
- Emacs: Universal Argument (C-u prefix arg)
- Emacs: Repeat Last Command
- Emacs: Jump to Previous Position
- Emacs: Narrow to Region