2012-05-22

The Roadmap to Completely Replace Emacs's Key System

Perm URL with updates: http://xahlee.org/emacs/emacs_keybinding_redesign.html

This post discusses a systematic way to replace emacs's one thousand keys.

Voice version of the blog at:

“roadmap to emacs key replacement”

The following is a text version.

massive update on the ergonomic keybinding.

It's dev version. Probably has bugs. More change coming in following days or weeks.

made few discoveries about keyboarding habit and health this week. Don't know where to begin… but i'll just start to ramble here. You can read on or just get the files there any try it. Read the history file there. More change will be done in next few days.

Ok, following will be rambling. (in the following, i'l use QWERTY notation. even though i use Dvorak.)

My left hand is fucked. emacs. Wasn't sure what's causing it. Now i know. It's the keys that require using 4th and 5th fingers, while hand is in standard touch-typing position. Actually, mostly the undo Z, cut X keys, and that standard save select all (S, A).

Here's a new thing i've learned. Normally, it's a good advice to press combination keys using both hands. That is, suppose you want to press 【Ctrl+x】. You should use right hand to hold right Ctrl and left hand to press x. But if you are a touch typer and leave your hand in standard position, so you press the x with 4th finger. That'll cause a major problem if done often.

Solution: set F1 F2 F3 F4 keys for undo cut copy paste.

there's lots of tricky details. Normally, for those who use Caps Lock for Ctrl, this particular issue doesn't happen, because you shift your left hand and make your left hand into some spider leg way to press 【Ctrl+x】. So, x is pressed by either 2nd or 3nd finger, both strong fingers. (though, i think given equal amount of typing, this method may develop other problems.)

also, there are certain things that made this issue worse: in about a year ago, a new feature is added to ergoemacs keybinding. That is, when there's no text selection, pressing cut or copy will simply cut/copy the whole line. (See: Emacs: How to Copy/Cut Current Line.) This is really a fantastic feature by itself. But there's a odd consequence. With this new feature, i noticed that i no longer use kill-line anymore. I simply use cut, which will cut the current line nicely. Also, when i need to cut/delete multiple lines, normally you mark, then move cursor, then cut or delete. But i noticed i don't do that anymore. I simply just cut multiple times, sometimes holding the cut key. Nice! Convenient and saves keystrokes. But the problem is, that my 4th finger now press the x key, many many times. In other words, indirectly, i'm putting a whole lots burden on the 4th finger on the left x. If i was hunt'n'peck, that may not be a problem because i just use index finger to peck x. But since i am touchtypest, and tend to follow proper ways, so to press x, i use 4th finger while whole left hand is in standard position. This is the the cause of my problem. Normally, standard typing won't type x much.

i find this particularly interesting, because seemingly good methods may create side effects that's bad.

so, in a summery, if you want to assign score for each key with respect to health, then the worst are Z X A S keys (and same for right hand). The interesting thing is that Home Row key ≠ good health key.

also, in past week, been spending days to think/search on what's the problem. Sometimes i think typing too much IS the problem, period, regardless all other health measures. That is certainly true to some degree. When you need to type more than certain load for years, one'll get problems regardless how good are the typing habits, keyboard, or personal health etc.

but anyhow, in past week's thinking, i came up with the thought of eliminating all combination keys. I've been on this road in recent years, but this week i made a more systematic approach, and added 30 or so sequential keys with the F key. By my analysis, i think sequential keys are much superior than key combos in many ways. Health, memorization, grouping... and i think even faster to operate on the long run on average. Here's a draft of reasons:

Advantages of sequential keys

  • easier to press
  • far more key possibilities (not technically, but indirectly due to the model of all single key, as opposed to mixed single/combo keys (e.g. 【Ctrl+x c】, 【Ctrl+x Ctrl+c】))
  • Easier to remember. (because now it's all single keys, as opposed to mixed single/combo)
  • commands can be grouped. e.g. 【F5 F6 …】 prefix for elisp related. 【F5 F7】 for editing related. 【F5 F8】 for rectangle* commands. 【F5 F9 …】 for modes. 【F5 F10 …】 for toggling commands, ….
  • help is easily available by pressing the sequence followed by F1. It'll show this group's commands, and each command are links to inline doc.

so, i've been using a draft system for a few days now. Been thinking to go thru the whole ~200 C-x keys to give them a sequential key, and make it part of ergoemacs. But that'll take months to design.

the one thing sequential keys can be faster is that, for example, 【Ctrl+x r k】 of kill-rectangle; you want to make the most frequently used commands to have the most easy keys. In this case, that key can be 【F7 F8 8】. So, 3 keys all nearby.

but 【Ctrl+x r k】 is easier to remember? Not necessarily. If you look at emacs's 【Ctrl+x r ‹key›】 (See: gnu_emacs_keybinding_C-x.txt) , you'll find it's a mixed bag. Some are about bookmark, some rectangle, some registry. While, 【F7 F8】 prefix can all be about rectangle commands. So, this is a example that i think sequential keys may not be worse with respect of ease of memorization.

but also, when it comes to keys, ease-of-press is more important than ease-of-memory. Because, once you know the key, you have to use it for the rest of your life. Also, the memory is muscle memory, not verbal citation of key sequence. When asking what's the key for a command, most emacs users may have difficulty, but will easily execute it the fingers.

so far, the system is such that for most frequently used commands, they'll have one single F key. e.g. F2=Cut, F3=Copy, F4=Paste, F5=Undo. Then, Secondary frequently used ones will have 2 keys, start with a F key then a number. e.g. 【F7 5】 for list-matching-lines. 【F7 6】for rect kill, 【F7 8】 for rect yank, etc etc. Then, others will have 3 keys, e.g. 【F7 F6 5】.

principle: 1 to 3 keys. The first few are always F keys. The last is digit or letter. (this makes it actually easier to remember than C-x, or C-c prefixes… many of them are more prefixes. Which is prefix is not predicable.)

Currently, the plan is that F6 to F9 are all prefixes. If we only use these 4 F keys, in our system, we'll have a total of 4*40+4*4*40 = 800 keys. Pretty much covers any need. (any emacs user, even advanced expert, probably use less than 200 keys.) (GNU emacs by default has about 800 usable keys. See: A Curious Look at GNU Emacs's 1000+ Default Keybinding.)

also note: combo keys are still necessary. Any command that needs to be called twice or more in one shot, must be combo keys. e.g. moving cursor, page up/down, undo, redo, paste, isearch-forward, tags-loop-continue, ... where you can hold it for repetition. (one single F key can also work, but there are not enough F keys for that, and plus F keys needs reach) So, these should be covered by 【Ctrl+‹key›】 or 【Alt+‹key›】.

Conversely, i think a principle of this is that if a command never needs to be called twice in a row, then it shall Not have one of 【Ctrl+‹key›】 or 【Alt+‹key›. That is, the combo keys will be exclusively for commands that may need to repeat by holding key. (many keys in emacs default violate this. e.g. query-replaceAlt+%】.) This way, we maximize the key space for any commands that needs it. While, once-off call commands such as {query-replace, goto-line, list-matching-lines, delete-matching-lines, grep, shell, calc, shell-command, find-file, dired, list-buffers, iswitchb-buffer, bookmark-bmenu-list, copy-to-register keyboard-quit, kmacro-start-macro, describe-function, …} will use the F key sequence space.

also, been thinking to abolish any key that needs pressing 3 keys simultaneously. e.g. emacs default regex replace, or lisp code navigation keys.

btw, this note apply to really heavy typers. there are huge number of misconceptions about typing. I have brushed with RSI in past years. Never seriously enough to experience pain, but seriously enough to do something about it. (tingling sensation, sore, etc. This time, it's soreness in forearm) About 2 years ago, there's a incidence of tingling, pretty bad. Blogged about that here: Programer Hand Health: vi Esc Key Syndrome, Emacs, RSI, My Experiences. In summery, that problem is caused by frequent side-to-side wrist motion. (like vi, reaching for esc) It was my bad habit of reaching for the 1 and ` key. This has since been corrected, but it's so interesting that today i developed other issue.

typing is such a complex and subtle thing... here's a blog i wrote that covers some common misconceptions of typing. It's a draft version, in bad shape... but anyway here it is Bad Advices from Programers about Typing and Keyboard (RSI)

this post is quickly written. I just want to get it out. Will edit and refine later. I actually typed the whole thing, lol, my hand didn't break (lol). Feel free to post your thoughts, even if disagree. Emacs keys needs to be based on scientific basis as much as possible, and it can be done…

PS check out the ergonomic keybinding update, give me your input. Thanks.

for a programer, as much as 70% of your typing is calling editing commands, not data entry.

that means, it's not QWERTY that wreck your hand. It's the emacs keys.

See: Emacs's Command Frequency.

Completely Replace Emacs's Key System

This leads to a key system that completely replace emacs's system. This i've been thinking for a few years now. But today, it seems i actually arrived at a sensible map. Here's a summery:

• First, start with ErgoEmacs Keybinding. This will take care of some 80% of key health issues.

• The Menu key will be emacs M-x. Single key. There will also be a combo key for this, provided in the rare situations when people don't have the Menu key. Currently, it's 【Alt+a】 in ErgoEmacs keybinding. There probably should be a single F key. (e.g. Mac users). Possibly F10.

F2=Cut, F3=Copy, F4=Paste, F5=Undo.

• The 【Ctrl+x ‹key›】 group will be mapped starting with a function key. Currently, the plan is F8.

• The 【Ctrl+c ‹key›】 group will be mapped starting with a function key. Currently, the plan is F9.

That leaves with emacs 【Ctrl+h】. But lucky for us, emacs already has F1 as equivalent.

The above is the sketch of the design. It's pretty much all already been implemented in ErgoEmacs keybinding. (except the C-c = F9 issue, probably due to a emacs bug, but we'll not discuss that for now)

What's really new, is to design the actualy F key sequence for each and every of GNU Emacs's 1000+ Default Keybinding, based on the principles in this article and that of ErgoEmacs. Also, the principles of this article is subject to change. The work will needs lots stats and experimentation.

I'll probably be working toward this, slowly, in coming months or years.