8

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 4

15

Evaluate the following using eval-expression (M-:) or in a scratch buffer:

(describe-key (kbd "C-<whatever>"))
2
  • 1
    Incidentally, you can find this solution using C-h k C-h k. (Works in my terminal.)
    – Kevin
    Sep 26, 2014 at 17:43
  • 1
    Great. It's actually better to use M-: or to evaluate it in your current buffer, as the keyboard shortcut might be mode specific.
    – asmeurer
    Sep 26, 2014 at 18:54
9

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.

3
  • Are there instances where you can type C-x but not C-a? All of these require the ability to issue C-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"
    – nispio
    Sep 26, 2014 at 20:10
  • 2
    C-a is a bad example. A more likely one would be C-A (or C-S-a), as terminals don't seem to like control + shift.
    – asmeurer
    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 used screen in a long time, so I could be remembering wrong. Sep 26, 2014 at 21:01
2

You could also use C-h bto look at all the keybindings, that will include mouse buttons and everything else.

1
  • After the describe-bindings help window pops up, you can also use isearch to search for the plain-text representation of a key sequence and the function it is bound to. Also, the package helm-descbindings will let you navigate all of the bindings in a helm buffer.
    – nispio
    Sep 26, 2014 at 20:53
0

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.

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.