Emacs Repeat Commands

Note: There are many different ways to repeat commands in Emacs

Today I will show you the main ways.

Using numeric arguments*

Caveat: This does not work with commands that prompt for input or if the numeric argument is being used in another way.

See my video on advanced Emacs Motions for details about numeric arguments

https://youtu.be/Ns6zK2iodfo

Using C-x z

Repeats the previous command

To repeat the command more than once, type additional z’s: each z repeats the command one more time.

Type a character other than z or press the mouse to end repetition

Repeat Mode

Activate via M-x repeat-mode

or add in permanently

(repeat-mode 1)

This repeats commands bound to two or more keystrokes:

C-x u => u u u
C-x o => o o o
C-x <left> => <left>

Feedback will be provided in the echo area so you see what single-key shortcuts you need to type to repeat the command

Note: Not all commands support repetition. To see which ones do:

M-x describe-repeat-maps

To exit the repeat process: type any character other than repeat key

Repeat "complex" commands, i.e. commands invoked via the minibuffer

C-x ESC ESC is used to re-execute a recent minibuffer command. With no argument, it repeats the last command.

It works by turning the previously invoked command into a Lisp expression

This helps you see the lisp form of interactive commands.

M-x menu-bar-mode

(menu-bar-mode 'toggle)

You can also alter the command by editing the Lisp expression.

Whatever expression you finally submit is what will be executed.

Return to Home