6

I know that emacs is often critzied because of its shortcuts. But this isn't the intention of that question! I come in peace! ;)

I was using vim for years. And I see a concept behind of the most shortcuts there. e.g. You don't have to move your right hand/fingers away from the basic-position on the keyboard to navigate in your file.

I did the emacs tutorial and couldn't get into it. Why are the shortcuts this way? Even the basic ones. They are hard to remember and hard to press. In my opinion I have to move and combine my fingers in a unnatural way.

It would help me to get deeper into emacs if I would understand the concept behind that keys. It was the same for me in vim. The first time it was damn crazy. But when I understood it everything went nice and easy. ;) I am looking forward to work with emacs the same way.

Another side question would be why are CTRL and ALT are renamed in emacs? From the viewpoint of a beginner it doesn't help. It just underline the "exoctic" status of that genius piece of software.

btw: I know the evil-mode and that emacs is able to modify nearly everything I want. But that shouldn't be the starting point for a emacs-beginner.

buhtz
  • 679
  • 4
  • 22
  • 7
    Actually, a good amount of them *is* mnemonic. According to Coders at Work, the current keybindings are a result of Guy Steele reconciling the six different popular Emacs keybinding sets at that time... – wasamasa Aug 16 '16 at 06:39
  • 2
    Don't look for a deeper meaning, where there is none. The default key-bindings are one of the worst parts of Emacs. – politza Aug 16 '16 at 07:25
  • 1
    I guess the usual pattern is "Make something out of modifier keys and the first letter of whatever describes what the command is doing". E.g. `C-b` (backward), `C-p` (previous line). Then in the fine print you'll find "if that doesn't work, be creative". – YoungFrog Aug 16 '16 at 12:04
  • I would say historical growing. Keys were added when needed, and never changed. – Arne Aug 16 '16 at 13:13
  • @Arne: Not true that keys have never changed, once added. What is true is that changing a commonly used default key binding involves a fair amount of reasoned discussion among Emacs developers and other Emacs users. One reason for this, but not the only one, is that users get used to things... But Emacs users have requested default changes, and such changes have occurred. Besides other reasons, including user-base habits, the fact that it is so easy to define your own preferred key bindings makes the choice of defaults less important. Nevertheless, Emacs takes defaults very seriously. – Drew Aug 16 '16 at 15:27
  • @Drew This sentence "the fact that it is so easy to define your own preferred key bindings makes the choice of defaults less important" gives me the feeling my finger nails just rolled up. – Arne Aug 17 '16 at 13:43
  • @Arne: Not sure what you mean, but I take it as a lighthearted Eureka! – Drew Aug 17 '16 at 14:47
  • @Drew Imagine a world where keyboard combinations of all programs are randomized per person but in a clever way so that they do not have conflicts with the operating system which also has randomized keyboard shortcuts. I mean it's not that much of a problem, because you can just change the configuration for all programs easily. The way you do it is also different in every program. But that's also not a problem, because it is configurable how you can define your keyboard shortcuts. – Arne Aug 17 '16 at 16:39
  • @Arne: [Do not pass GO; do not collect $200](https://www.youtube.com/watch?v=TIoBrob3bjI). ;-) – Drew Aug 17 '16 at 22:06

1 Answers1

7

Unlike vi, Emacs does not have two completely separated modes, one for issuing commands and one for inserting text. This means that self-inserting keys such as letters self-insert (duh). And that means that they cannot simultaneously be used to invoke commands (other than the command to self-insert -- in Emacs all user interactions invoke commands, in fact).

So Emacs had to use other key combinations to invoke commands. (And this was also before there were things like a mouse, graphic-display, and window managers.) The ASCII control keys, using the Ctrl key, were the natural answer. Using them you can mix self-inserting keys with command-invoking keys.

There is only one Ctrl key, so the commands you can invoke using it are (were, especially, at the time Emacs was created) limited in number. There is also the Escape key (ESC) key, and that too was put to use for invoking commands, as a prefix for key sequences.

There is also an Alt key (aka Meta, typically), which in some cases allowed for a shortcut from using ESC-prefixed keys.

Most key typing involves self-inserting keys. A minority involves invoking commands. So this combination worked pretty well.

Beyond that is the question of which key sequences to use for what commands. This was carefully worked out, with experimentation -- and it continues to be. Here are some of the basic ideas, which other posts here might go into, and which you can easily find more about elsewhere:

  • Often-used commands, and often-used sequences of commands, should have relatively easy-to-use key sequences. Commands used less often can have harder-to-use keys.

  • Seldom-used commands need have no key sequence. Any command can be invoked using a simple-to-use key (M-x) that prompts for you to enter its name.

  • Keys easy to reach by the stronger, longer fingers and the thumbs are generally easier to use often. This means keys like f, e, g, v, b, j, i, o, m, n, SPC, DEL (Backspace), etc.

  • Because there are many commands, and thus many command-invoking key sequences, users need some help keeping track of them. For this, Emacs defined help keys, including C-h c and C-h k, which describe keys, and C-h w which tells you what key to use for a command name you type at the prompt. This is behind the strong commitment that Emacs be a self-documenting editor - just ask it about itself. At the time Emacs was created, this was a new idea, and it is still an idea that is stronger in Emacs than elsewhere.

  • For the same reason, some degree of organization of the many key sequences, providing some symmetry and other mnemonic aids, was called for. This is behind the system of using C-f, M-f, C-M-f, C-b, M-b, C-M-b, etc., with "f" signifying "forward" and "b" standing for "backward".

The rest is history: evolution, adaptation, suggestions and experiments by thousands of people.

Oh, did I forget to say that because Emacs uses modifier and prefix keys to invoke specific commands, binding keys to commands is very important, and because it is important, users need to be able to do this themselves? This is behind the strong commitment that Emacs be a customizable editor.

Predefined keys have no special significance. With a couple of somewhat-exceptions (you usually should not mess with C-u, ESC, or C-g), you can easily create your own system of key bindings - you can pretty much replace any and all of the predefined key bindings.

Does this help understand Emacs keys? It should help understand Emacs more generally, because in Emacs, everything -- every single user action, is a command. And any command can be bound to a key. Many commands are bound to keys by default, and you can bind others or rebind any that are bound.

In the end, the Emacs "crazy" keys are your own fault, in this sense: predefined keys are offered as a suggestion - something suggested that you can use out of the box, if you want. But you can easily create your own crazy-keys combinations and systematize things your own way.


"Another side question would be why are CTRL and ALT are renamed in emacs?"

Those are common labels for the physical keys. In Emacs (and other programs), there is a distinction between physical keys, the codes they send to applications, and the software representations of those codes.

In Emacs there is more than one soft representation of keys. In particular, there is an external, user-facing key-description representation, such as C-x 2 or <M-down> or C-M-f, which is what you provide to function kbd when you want to bind a key sequence. And there are internal, Emacs-Lisp representations, such as [M-down] and [(meta down)].

The aim of the external, user notation is to be succinct: C-M- instead of Ctrl + Meta, etc.

The reason Meta is used instead of Alt is that in fact both can be used. Alt is a physical key; you can move Meta pretty much wherever you like. Emacs users and programs generally use Meta, which is separated from hardware, instead of Alt, which is not. And they generally just accept the default assignment of Meta to the Alt key.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • 2
    Just to point, Meta was an actual key modifier on Lisp machines from the 80s. Standard PC keyboards never had one, so it was remapped to Alt – Miyamoto Akira Aug 16 '16 at 17:37
  • 1
    Emacs as the family of editors is older. Can't say when Meta was introduced. http://ergoemacs.org/emacs/emacs_kb_shortcuts_pain.html and https://kb.iu.edu/d/aghb seem to think that it comes from the Meta key on Lisp machines. Doesn't seem logical to create a Meta key modifier without the actual key on a keyboard. – Miyamoto Akira Aug 16 '16 at 18:58
  • @MiyamotoAkira: It's possible that the first use of Meta in Emacs was borrowed from its use on a Lisp machine; I don't know. In any case, Emacs using Alt for Meta predates Emacs on PCs or with PC keyboards. Most use of Emacs in the 80s was on minicomputers and workstations. – Drew Aug 17 '16 at 04:49
  • Should `C-g` be also added to the bindings that should not be touched? – Kaushal Modi Aug 17 '16 at 12:20
  • This is a great explanation! Thank you very much! This help me a lot to get deeper into emacs. And it also help me to reflect myself as a editor-user. ;) – buhtz Aug 17 '16 at 14:19
  • 1
    This text should published somewhere! – buhtz Aug 17 '16 at 14:19
  • @KaushalModi: Yes, probably `C-g` too. I've added that. Thx. – Drew Aug 17 '16 at 14:43
  • 2
    As one of the earliest users of emacs, I can report that the Meta- modifier was from a system called the Knight TV (terminal), used at the MIT AI Lab. It had a keyboard we jokingly called the "Space Cadet" keyboard. It actually had (IIRC) **five** modifier keys (Shift, Ctrl, Meta, Super, and Hyper). The LispM keyboards were modeled after these (actually, the first two LispMs [Cons and Cadr] used the Space Cadet keyboards originally). – MAP Aug 19 '16 at 08:01
  • @MAP: Good to know; thanks for contributing that. I guess (?) you are also saying that that terminal predates any use of Meta by Emacs, in addition to predating its use by Lisp machines. – Drew Aug 19 '16 at 19:22
  • This could be a "Space Cadet" keyboard? http://xahlee.info/kbd/lisp_kbd/Symbolics_keyboard.jpg – buhtz May 28 '19 at 06:44