I know that to repeat the last command, there is C-x z and then to keep using z to easily keep the last command in operation, but what can be done for the 2nd or 4th last command? Or is that information lost?

2 Answers 2


What @Dan said is correct, and it answers your question, which is about any command repeated in any way -- including a command invoked using a key bound to it.

Here is some additional information, which pertains only to so-called complex commands, which means those executed via M-x.

  1. Command repeat-complex-command, bound to C-x ESC ESC, gives you access to the complete complex-command history. And you can access any command in the history directly by way of a prefix argument -- e.g., M-2 means access the second-from-last command.

  2. If you use library cmds-menu.el (see Recent Commands Menu) then you can access any command in the history directly by choosing it in the menu-bar menu Tools > Recent Commands.


As far as I can tell, in its current implementation, only the most recent command is kept. Everything before that is lost.

I looked at the source code for repeat (the command to which C-x z is bound), and it uses the variable last-repeatable-command. Its docstring reads:

last-repeatable-command is a variable defined in C source code.



Last command that may be repeated. The last command executed that was not bound to an input event. This is the command repeat will try to repeat. Taken from a previous value of real-this-command.

So last-repeatable-command stores an atom, not a list, and gets overwritten with the value of real-this-command every time you invoke a command.

  • do you think there is somewhere else where the previous commands are stored? EG. when changes are 'undone' is it just the track record in the file or the actual commands that performed these changes?
    – Vass
    Commented Jan 24, 2017 at 23:50
  • @Vass: I don't know, but I doubt it. You could create your own list by consing this-command onto the front of a running list of commands, calling it from post-command-hook.
    – Dan
    Commented Jan 24, 2017 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.