Emacs: Repeat Last Command

By Xah Lee. Date: . Last updated: .

Here are 2 useful commands to increase emacs use efficiency. repeat-complex-command and repeat .

Command: repeat-complex-command

One command i use few times a day is repeat-complex-command. This command is great for:

For example, Alt+x query-replace and type the search text and replacement text. [see Emacs: Find Replace in Current File]

Now, to do that again, you can Alt+x repeat-complex-commandCtrl+x Alt+:】. Now you don't have to type the search/replacement text again.

But, the extra beauty here is that it shows the elisp code that's actually called. In this case, it's this

(query-replace "aa" "bb" nil (if (use-region-p) (region-beginning)) (if (use-region-p) (region-end)) nil nil)

(it might be slightly different on your emacs setup)

This is very useful because:

Command: list-command-history

Alt+x list-command-history is a very useful command. It list all recent commands called by Alt+x.

Command: repeat

Another useful command is Alt+x repeatCtrl+x z

It repeat most recently executed command.

What makes it very useful is that, 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 forward-word 4 times.

This is especially useful to run last keyboard macro call-last-kbd-macro, which does not have a shortcut key. [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.


Emacs Tutorial

Quick Start

Font

Split Window

File

Buffer

Copy/Paste

Find Replace

Unicode

Whitespace

Rectangle Edit

Line Wrap

Shell

View Special File

Editing Brackets

Org Mode

HTML

Emacs Efficiency

Misc