I am trying out a new major mode, how can I take advantage of Emacs' documentation system to get a listing of key bindings available in that specific buffer?
8 Answers
C-h b
will list all the bindings available in a buffer. This is a mnemonic for help (C-h) bindings (b).
You can also get a list of keybindings via C-h m
, which is help for the major and minor modes for the buffer. The formatting of this is a little clearer, but includes additional information about the modes beyond just listing the keybindings.
-
Thanks, I wanted to know this earlier today and blanked on how to do so.
C-h m
is the one I remember using a long time ago, but forgot.– nixeagleCommented Oct 6, 2014 at 19:43
I use the command helm-descbinds
, which is available via melpa. I mapped it to C-h b
because it is basically a drop-in replacement for describe-bindings
. The benefit is that it is easier to navigate and search than the output of describe-bindings
because you can easily search for keywords and the helm buffer will narrow to show all of the matches, and which mode they come from
For any selection in the list, you can choose to either perform the action, or to jump to the documentation for the command.
-
With latest versions of helm-descbinds (or perhaps before), you don't need to explicitly bind
C-h b
to helm-descbinds. Instead just activate the helm-descbinds-mode. ThenC-h b
will invoke it. De-activate the mode andC-h b
is rebound to its default.– PRouleauCommented Oct 30, 2023 at 21:37
Although not the canonical emacs
way of doing things, I quite like using discover-my-major
for that purpose because it just feels more effective.
It is available on melpa
and is powered by the makey
library, which is responsible for those nice menus magit
is known for.
I'd suggest you check out the github
link for a screenshot demonstrating the functionality.
Install it (I'd suggest from melpa
using package.el
) and add
(require 'discover-my-major)
(global-set-key (kbd "C-h C-m") 'discover-my-major)
to your config.
Currently, probably the best way to discover keybindings is by using the which-key package. This package is central in distributions like Spacemacs and Doom emacs.
It provides various commands for discovering available keybindings, e.g. which-key-show-top-level
and the which-key-show-(full)-major/minor-mode(-keymap)
s.
The which-key buffer can be shown persistently by setting which-key-persistent-popup
to t
.
Here is a screenshot of the Info-buffer in Spacemacs with which-key showing the major mode keybindings:
Icicles key completion gives you all of the info you get from C-h b
(describe-bindings
), C-h w
(where-is
), and C-h c
(describe-key-briefly
), rolled into one. Just hit S-TAB
anytime at top level.
Every key sequence that you can possibly type in the current context (with the exception of keys such as
q
that just insert characters) is displayed in buffer*Completions*
. This tells you which keys are available now.The command that each key sequence is bound to is also shown in
*Completions*
, next to the key name (e.g.b = bookmark-jump
). This gives you a rough idea what the key (e.g.b
) does.Each key sequence that is bound locally, that is, each key that has a special meaning for the current buffer mode, is highlighted in
*Completions*
with a pale yellow background. This tells you which bindings are those offered by the current mode.Click
C-M-mouse-2
on a key name (with its command name). A*Help*
buffer opens with a complete description of the command bound to the key. This tells you what the key sequence does in detail.- Click another key (command) to get help on it, and so on… You can do this all day, browsing through the available key bindings to learn what they do. This is a great way, in particular, to learn about the keys defined by a given mode.
- Click any link in the
*Help*
buffer to find out about stuff related to a given command and its key sequence. Navigate throughout the help system – you can do this all day too. Then pick another key to interrogate…
If you want to then use a key (command), then just click
mouse-2
on its name in*Completions*
(or complete the key + command name and hitRET
). Or cancel, usingC-g
, and hit the key as you would normally.
You can start with S-TAB
, to see all currently available keys. Or you can start by hitting a prefix key (e.g. C-x
) and then hit S-TAB
to see all keys that have that prefix (i.e., all keys available after you have hit that prefix key). (The "command" associated with a prefix key is indicated by ...
.)
You can even complete menu-bar menus this way, by accessing the pseudo-function prefix key menu-bar
.
See also this description
You may want to look at C-h m
that lists all key bindings of major mode and minor modes. Read more about other Help commands here. Emacs help system is rich.
Although not exactly what you are looking for you might want to try out guide-key. If you enter a prefix sequence without completing it guide-key will pop up a buffer showing you the available completions and what functions they execute. I find this very useful when I need to learn new bindings in Emacs.
-
8
In plain emacs you can do
- 'C-h m' to show help for current major and minor modes and their commands
- 'C-h b' to show all key bindings
- after prefix command 'C-h' to show bindings starting with prefix
If you use which-key it will display the available keybindings on minibuffer and after prefix command 'C-h n' 'C-h p' will be used to change pages on minibuffer, to show bindings for prefix like plain emacs you will need 'C-h h'