Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: print key binding for a command or list all key bindings

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.

like image 808
Yktula Avatar asked May 16 '10 23:05

Yktula


People also ask

How do you bind commands in Emacs?

Keys can be bound to commands either interactively or in your . emacs file. To interactively bind keys for all modes, type M-x global-set-key RET key cmd RET . To bind a key just in the current major mode, type M-x local-set-key RET key cmd RET .

What is RET key in Emacs?

"RET" is the Return key while emacs runs in a terminal. and run emacs in terminal, your keybinding will have no effect. But the problem is, by binding (kbd "RET") , you are also binding (kbd "C-m") , regardless you run emacs in terminal or GUI.

What is Vim Keybindings?

Keymapping or Key binding is a process in which a user or a system can assign certain keys or commands to perform a particular task or commands. This can be quite useful in Vim as well as in other text editors to avoid some repetitive tasks and save time.


1 Answers

  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.

like image 131
Matt Curtis Avatar answered Oct 02 '22 08:10

Matt Curtis