I know that I can look up help for a key sequence using C-h k <key sequence>
, but I use Emacs in the terminal, and my terminal emulator doesn't pass all key sequences through to Emacs. Sometimes I'll see the notation for a given key sequence written somewhere without explanation, and I want to look up what it does, but I can't even type it. Is there an equivalent to C-h k
where I can just type the key sequence (like literally C-<character>
)?
4 Answers
Evaluate the following using eval-expression
(M-:) or in a scratch buffer:
(describe-key (kbd "C-<whatever>"))
-
1Incidentally, you can find this solution using
C-h k C-h k
. (Works in my terminal.)– KevinCommented Sep 26, 2014 at 17:43 -
1Great. It's actually better to use M-: or to evaluate it in your current buffer, as the keyboard shortcut might be mode specific.– asmeurerCommented Sep 26, 2014 at 18:54
If you can't use a particular key combination because of your terminal, you can often fake it by manually simulating the key modifier. The following combinations work exactly as though you had used the corresponding modifier key:
C-x @ a alt
C-x @ m meta
C-x @ c control
C-x @ h hyper
C-x @ s super (lowercase s)
C-x @ S shift (uppercase S)
For example, if you can't type C-a
for whatever reason, C-x @ c a
is the same thing. If S-<return>
doesn't work at your terminal, C-x @ S RET
will. These key combinations work with the C-h k
help prefix, too.
-
Are there instances where you can type
C-x
but notC-a
? All of these require the ability to issueC-x
. Being able to use "hyper" or "super" modifiers without a dedicated key seems like it could come in handy. I have encountered a terminal that was not set up to map the "alt" key to "meta," but I worked around it (grudgingly) using "ESC"– nispioCommented Sep 26, 2014 at 20:10 -
2
C-a
is a bad example. A more likely one would beC-A
(orC-S-a
), as terminals don't seem to like control + shift.– asmeurerCommented Sep 26, 2014 at 20:19 -
I seem to recall that under
screen(1)
,C-a
is commandeered to be a multiplexing key of sorts. But I haven't usedscreen
in a long time, so I could be remembering wrong. Commented Sep 26, 2014 at 21:01
You could also use C-h b
to look at all the keybindings, that will include mouse buttons and everything else.
-
After the
describe-bindings
help window pops up, you can also useisearch
to search for the plain-text representation of a key sequence and the function it is bound to. Also, the packagehelm-descbindings
will let you navigate all of the bindings in a helm buffer.– nispioCommented Sep 26, 2014 at 20:53
I wasn't aware of any of these more specific solutions, and they probably work better if you want the exact command that is executed by a key.
However, for a more general tip on finding help, if you do in fact have a sort of vague idea about what the key binding is doing, but want more details, I've used C-h f
(or describe-function
) with tab completion to try and find the name of the function, which often works, and then the help will tell you if that function has a binding. And when that hasn't worked, I've used C-h a
(or apropos-command
) and typed in some terms that I thought might be related and surprisingly, I've had a lot of success finding the correct command for the key binding. Another good option is C-h m
(or describe-mode
) and look at all the key bindings for the current mode. This can also be used as helpful terms to use for either or the previous two search techniques.