3

C-h b shows the key bindings. But I can not see, which prefix is left for my own functions. Is any prefix reserved for user bindings?

Drew
  • 75,699
  • 9
  • 109
  • 225
ceving
  • 1,308
  • 1
  • 14
  • 28
  • **All keys** are available for users to rebind as they like. *All of them.* But when you say *"left"* do you mean **reserved** for users? If so, see @Gilles's answer. – Drew Jul 06 '21 at 22:24
  • Unfortunately, Emacs dropped the ball on systematizing key bindings. If you use Emacs long enough, you're eventually going to acquire enough custom functions that you won't be able to find convenient bindings for them all, and/or won't be able to remember them, unless you do what the Emacs developers should have done a long time ago, which is adhere to a consistent philosophy of how to choose bindings. In the long run, I think it's too confining to try to stick to Emacs's own keybindings for everything. Of course, I wouldn't change them willy-nilly, but I recommend giving precedence to your ow – Addlai Jul 25 '21 at 10:58

3 Answers3

7

As stated in the manual:

A small number of keys are reserved for user-defined bindings, and should not be used by modes, so key bindings using those keys are safer in this regard. The reserved key sequences are those consisting of C-c followed by a letter (either upper or lower case), and function keys F5 through F9 without modifiers

In practice, C-S-letter is not officially reserved but I don't remember ever seeing a mode using it.

Additionally, some standard bindings on control-letter combinations tend not to be useful because you can use the arrow keys instead. This gives you C-p, C-n, C-b and C-f. Also C-a and C-e if you have Home and End keys. And all standard bindings only use the modifiers Ctrl, Shift and Meta (C, S, M) (or if there's any standard binding using another modifier, it duplicates another binding because those are the only three modifiers that everyone has), so if there's another modifier on your keyboard and it isn't reserved by your window manager, you can use that.

You can also free Ctrl+H, Ctrl+I, Ctrl+J and Ctrl+[ by using Tab, BackSpace, Return and Escape instead, however those are trickier to use because the function keys are processed as the control-character combinations in Emacs. For example, TAB is the same thing as C-i, so if you want to give Ctrl+I its own binding, you have to re-route it to something that is not C-i. See How to bind C-i as different from TAB?

  • 2
    A lot of people using the Emacs GUI will rebind `C-z` as well, since they don’t need a shortcut for iconifying an Emacs frame. Even in a terminal you have the option of opening a shell inside Emacs rather than suspending Emacs to use the shell. – db48x Jul 06 '21 at 11:55
  • Does the link at the end work? In my case (Chrome on Fedora 33) it appears as a plain text URL, but when I try to edit the answer, it appears as a proper link - canceling out of the edit leaves it as a plain text URL. What the ...? It's plain text on Firefox as well. – NickD Jul 06 '21 at 13:35
  • @NickD Looks like a bug in the server-side markdown→HTML renderer. It does render as expected in the preview, which is a link to a question on the same site where the text is the question title. – Gilles 'SO- stop being evil' Jul 06 '21 at 13:53
  • 1
    But at least [org-mode](https://orgmode.org/orgcard.txt) violates this convention, because it uses `C-c a` and `C-c l`. – ceving Jul 06 '21 at 15:57
  • 1
    Those are suggested key bindings. IOW, you have to take action to set them that way (or not). See https://orgmode.org/manual/Activation.html#Activation – NickD Jul 06 '21 at 16:30
  • "In practice, C-S-letter is not officially reserved but I don't remember ever seeing a mode using it." -- I imagine that's because such key sequences are troublesome on terminals. Urxvt, for instance, uses Ctrl+Shift for typing unicode. Maybe I'm mistaken, but it's my impression that Ctrl+Shift is not generally detectable from terminal programs. – JoL Jul 06 '21 at 19:34
  • @JoL Indeed, C-S-letter is not distinguishable from C-letter in most terminal emulators, and some terminal emulators use it for their own bindings. That's why standard bindings tend to avoid these, but it isn't a compelling reason since C-punctuation is also impossible to enter in most terminal emulators but it's used by several packages. – Gilles 'SO- stop being evil' Jul 06 '21 at 19:50
  • "if there's another modifier on your keyboard and it isn't reserved by your window manager..." -- I've never used a window manager that I didn't reconfigure almost immediately to stop conflicting with my Emacs keybindings. In general, I disable all key bindings that I don't *need* from a window manager, and ensure the remainder are bound to non-conflicting keys. – phils Jul 07 '21 at 04:18
  • My advice: As well as making use of additional modifiers, use the *most* accessible non-conflicting regular keys as prefix bindings -- you can follow such a prefix key with *any* key(s), and therefore bind any number of custom commands to easy key sequences. – phils Jul 07 '21 at 04:23
  • Super is no option, because I use it already for my window manager. Hyper may be an option, if I redefine my right Ctrl. – ceving Jul 07 '21 at 08:06
  • I have to admit, I almost fell out of my chair to see you recommending using arrow keys in preference to C-p, C-n, C-b, C-f, C-a, and C-e. I would never dream of doing that, because of the loss of speed and the fatigue from the constant hand shifts to do that. But to each his own. – Addlai Jul 25 '21 at 11:21
2

Just override any key that you don't use. Check what (if anything) is binded to a key with C-h k or install which-key-mode. You could also install something like worf or hydra make more room.

vcmsxs
  • 431
  • 2
  • 8
  • However, if the binding is global, you need to check whether the binding conflicts with anything in every mode you use. A key sequence that is not bound when you're in your init.el file (hence in Emacs-Lisp mode), might well be bound in, say, Python mode. – Addlai Jul 25 '21 at 10:17
2

Not yet mentioned, I'd like to recommend re-binding one of C-- or M--, since they both serve the same purpose. Then you have an entire key free to use.

bewilderex63
  • 140
  • 3