Is there a place where emacs stores commands the user has recently executed, in particular via keyboard shortcuts, and if not, would it be possible to tell it to store them somewhere? I sometimes type the wrong keyboard shortcut by accident and I don't know what it is that I did. I undo it, but I tend to repeat these accidental shortcuts every once in a while, and I have no idea how to find out what exactly I pressed or what command I ran.

I know how to determine what command is bound to a key. My issue is that I know neither the command nor the keys I pressed, only what effect they had and the fact that I recently did it.

  • 1
    Although some functions expressly set last-command to something special, for the most part you can just check the value of that variable to see the most recent last command.
    – lawlist
    Commented Jul 28, 2017 at 0:42

2 Answers 2


When some key sequence triggers an unexpected command, use view-lossage (bound to C-h l by default) to see what keystrokes Emacs has recently received. This is most useful since Emacs 25 as it now also shows the commands invoked by each key sequence. In earlier releases you'll just see the raw keystrokes.

  • 1
    The worst part is that the keystrokes C-h l (or worse M-x view-lossage) are included in this short list of recent-keys. So you better type that as soon as you notice the wierdness
    – Bae
    Commented Oct 13, 2020 at 1:41

As @glucas has mentioned, view-lossage helps. Unfortunately, it displays relatively few events, and users have no control over the number.

As C-h k C-h l tells you, you can record all keyboard characters by using open-dribble-file:

view-lossage is an interactive compiled Lisp function in help.el.

It is bound to C-h l, <f1> l, <help> l.


Display last few input keystrokes and the commands run.

To record all your input, use open-dribble-file.

open-dribble-file is an interactive built-in function in C source code.

(open-dribble-file FILE)

Start writing all keyboard characters to a dribble file called FILE.

If FILE is nil, close any open dribble file. The file will be closed when Emacs exits.

Be aware that this records ALL characters you type! This may include sensitive information such as passwords.

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.