2

Stupid question, but: how to press C-( (this is a default bind in Prelude Emacs for Smartparens's sp-backward-slurp-sexp)? On my keyboard i have such bracket only in same key with 9.

  • Hold control and shift and then press 9? – Tyler Apr 8 '16 at 20:19
  • @Tyler damn, rly seems to work, but i thought control+shift is another one modifier, cuz i have C-S-<up> and other arrows for buffer-move. – Flowneee Apr 8 '16 at 20:22
  • C-( is the same as C-S-9 – Tyler Apr 8 '16 at 20:24
  • @Tyler thx for explanation. One more thing: so i cant make smth like C-S-P (or other uppercase letter)? And maybe u will post ur comment as answer? i think this can be helpful for newcomers like me. – Flowneee Apr 8 '16 at 20:27
  • 2
    @Flowneee To figure out the key notation, do C-h c followed by the key combination you need to bind something to. If something is already bound, you will see that that is, or you will simply see that that combination is not bound to anything. For example, if you do C-h c followed by Ctrl+Shift+9 in an emacs -Q session, you will see C-( is undefined. So you need to bind your command to (kbd "C-("). – Kaushal Modi Apr 8 '16 at 20:34
6

This is a convention when describing key bindings in text. C indicates the control key, M the meta key (the alt key on most keyboards), and S indicates the shift key. The shift key is not normally listed explicitly. Instead, you would refer to the symbol that you get when holding the shift key.

For instance, the command set-mark-command is bound to C-@. To actually type this key, you would press C-S-2. Or in your example, C-( is entered by pressing C-S-9. (this assumes you're using a US keyboard, where @ is on the 2 key, and ( is on the 9)

One other note: for key combinations that combine the control key and a letter, the shifted letters do the same thing as the unshifted letter by default. That is, C-S-a (C-A) is the same as C-a. The same is true for meta. Meta + a shifted letter (eg. M-S-a) does the same as meta + the unshifted letter (e.g., M-a).

However, if you wish you can change this by explicitly binding the shifted letter to a different command. See the manual section (emacs) Modifier Keys for more details on this.

Finally, note that all of this is in reference to how we communicate about key bindings. As @KaushalModi points out, when it comes time to actually make a keybinding in your init file, you don't include the S-, you actually enter the shifted key. That is, you use

(kbd "C-(")

and not

(kbd "C-S-9")
  • 1
    I'd like to add that the convention is to use S when doing something like Ctrl + Shift + <alphabet>. So in the case of "Ctrl + Shift + p", it would be (kbd "C-S-p"). So rather than remember rules when to use or not use S in the bindings, it's better to just do C-h c (or C-h k) followed by the key combination you are interested in binding, to get the correct key notation. – Kaushal Modi Apr 8 '16 at 20:48
  • .. and for "Alt + Shift + p", it is (kbd "M-P") :) – Kaushal Modi Apr 8 '16 at 20:55
  • @KaushalModi actually, for Ctrl + letter, it doesn't matter if you use S- or not, captials and lower case letters are always treated the same. I didn't realize that before! – Tyler Apr 8 '16 at 21:04
  • Hmm, but I do have M-f and M-F bound to different things and they call different commands as I would expect. – Kaushal Modi Apr 8 '16 at 21:07
  • 3
    You CAN bind C-A and C-a to different commands; just that C-A is the wrong representation; C-S-a is the right one. Try out (global-set-key (kbd "C-S-n") #'previous-line) in emacs -Q; C-n will do next-line but C-S-n ("C-N") will do previous-line. – Kaushal Modi Apr 8 '16 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.