108

In Emacs (GNU 23.2, *nix), how can I:

  1. list the key sequences bound to a particular command? For example, how can we list all the key sequences that execute save-buffers-kill-emacs, with the output of key sequences bound to it? Assuming we can do this, listing the key sequences bound to goto-line should print the output: M-g g on a default install.
  2. list all key-bindings? Does C-h b do this? Would it print my own bindings?

I am aware that executing the command directly can print a key sequence it can be activated with, but it doesn't always do so, and a few things happen, including:
(1) the output doesn't remain for long, (2) the command is executed.

I want a command that lists for me (preferably all) the bindings attached to a given command, without executing the command, or something like that.

Yktula
  • 14,179
  • 14
  • 48
  • 71

2 Answers2

143
  1. C-h f (or M-x describe-function) will show you the bindings for a command.

  2. You are correct, C-h b (or M-x describe-bindings) will show you all bindings. C-h m (M-x describe-mode) is also handy to list bindings by mode.

You might also try C-h k (M-x describe-key) to show what command is bound to a key. For instance, on my machine save-buffers-kill-emacs isn't bound to anything, but C-h k C-x C-c tells me that C-x C-c is bound to save-buffers-kill-terminal. It will list all bindings for the command at the same time.

Matt Curtis
  • 23,168
  • 8
  • 60
  • 63
  • 11
    +1, Also there is `C-h c` (or `M-x describe-key-briefly`) which just gives the function that a key is assigned to in the mini-buffer space. – Shannon Severance Oct 27 '10 at 21:48
  • Not sure if this should be a separate question, but is it possible to show all keybindings/functions which start with a particular key? For example, what bindings *start* with ? Pressing after "C-h m" does not work as Emacs is waiting for a second key. – SabreWolfy Apr 26 '12 at 08:30
  • 1
    Asked as a new question here: http://stackoverflow.com/questions/10330510/show-emacs-keybindings-which-start-with-a-particular-key – SabreWolfy Apr 26 '12 at 09:17
42

How about just

M-x where-is <COMMAND>

You get the same information as you'd get with C-h f.

Also bound to C-h w, <f1> w and <help> w.

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
  • 2
    This is actually the correct answer to the first question, since `describe-function` doesn't list all bindings for functions like `ignore` or `self-insert-command`. – David Ongaro Nov 03 '18 at 20:17