Xah Lee, 2007-07, 2008-08, 2008-09
Emacs's default keybindings are very ergonomically painful, for several reasons. (For detail, see: Why Emacs's Keyboard Shortcuts Are Painful.) This page shows a redesign of emacs's shortcut set, based on ergonomic principles.
Here's the outline of how this design is arrived.
All the commands that has a default shortcut of M-‹key› and C-‹key› are considered. This command set is then ordered by their frequency of use. Then, commands with higher frequency of use are mapped to the most easy-to-press keys. Specifically: M-‹key› combination is considered easier than C-‹key› combination, home keys are easier than non-home keys, and keys pressed by the 2nd and 3rd fingers are better than keys pressed by the 4th finger and 5th fingers. (this design principle is similar to the design principle of Dvorak keyboard layout↗.)
(For a statistics of command frequency, see Emacs Commands Frequency.)
Secondarily, similar commands are placed together. For example, forward-char, backward-char, previous-line, next-line (these are the arrow key commands) are all mapped to the right hand's home position in a inverted T layout. Copy/cut/paste are in a row and adjacent to each other. By placing similar commands together, the keyboard shortcuts are made easier to remember. If we strictly go by command frequency with ease-of-key-press, then similar commands will be scattered all over. By placing similar commands together, the logical positioning makes it more coherent and easier to use, with no decrease in speed of execution. (because keyboard shortcuts are not executed continuously like typing.)
Of Emacs's shortcut set, the most frequently used commands can be grouped into 3 categories: (1) Those move the cursor. (2) those manipulate text. (3) Other. Cursor moving commands include moving the cursor to beginning/ending of char/word/line/sentence/paragraph/screenful/file. Text editing commands includes copy/cut/paste, paste previous (yank-pop), kill-word, backward-kill-word, kill-line, and some text transformations such as fill-paragraph, just-one-space, comment-dwim, etc. Also, commands such as mark-paragraph, are considered in this group. The third group, are commands such as execute-extended-command (M-x), keyboard-quit (C-g), toggle-input-method (C-\), universal-argument (C-u), help system (C-h ‹key›) etc.
In the Dvorak layout design, all vows are placed on the left hand's home row, and the most frequently used consonants are placed on the right hand's home row. The idea is that hands will alternate. We borrow this idea, by placing all cursor movement commands under the right hand, and all text editing commands (such as copy/cut/paste/kill-word/kill-line) under the left hand.
In this design, only the M-‹key› space is used. (and with some Meta-shift definition as well). The Ctrl+‹key› space are not used except 7 standard keybindings (Open, Close, Save, Save As, Print, Select All). This is so to avoid radical change that will require a lot coding efforts on every major and minor mode's keymaps. Emacs's default shortcut does not put much weight on the Meta+‹key› space, and does not use Meta+Shift+‹letter› space. By using the single-key shortcut space of M-‹key›, the operation and consistency of emacs's shortcuts are practically unaffected, while the most frequently used commands now have home-row keystrokes with the thumb down.
The following shows the layout of this design.
In this design, the layout is the same on QWERTY and Dvorak, because it is based on finger positions and not on command name's first letters.
1 del win del other win |
2 split win horz split win vert |
3 |
4 |
5 qry rep rex qry rep |
6 |
7 |
8 |
9 |
0 |
- |
= |
Backspace |
q fill/unfill ¶ |
w shrink spaces |
e ⌫w |
r ⌦w |
t |
y |
u ←¶ ←w |
i ▲ ↑ |
o →¶ →w |
p recenter |
[ |
] |
\ |
a shell cmd M-x |
s prev pane next pane |
d ⌫ |
f ⌦ |
g |⌫ ⌦| |
h →| |← |
j |◀ ← |
k ▼ ↓ |
l ▶| → |
; isearch← isearch→ |
' cmt dwim |
Enter |
|
z redo undo |
x ✂ |
c copy |
v paste↑ paste |
b |
n |
m |
, |
. |
/ toggle case |
|||
Alt |
Space mark-paragraph set-mark-command |
|||||||||||
Layout shown in png: ergonomic_emacs_layout_qwerty.png
Red colored commands means holding down the Alt (Meta) key. This colored commands means holding down both Alt and Shift. A blank key means it is unaltered from emacs's default command keybinding for that key.
For clarity, some command names are replaced with glyphs. Here's what they mean:
← backward-char → forward-char ↑ previous-line ↓ next-line ←w backward-word →w forward-word ←s backward-sentence →s forward-sentence ←¶ backward-paragraph →¶ forward-paragraph |← move-beginning-of-line →| move-end-of-line |
▲ scroll-down (page up) ▼ scroll-up (page down) |◀ beginning-of-buffer ▶| end-of-buffer isearch← isearch-backward isearch→ isearch-forward |
⌦ delete-char ⌦w kill-word ⌦s kill-sentence ⌦| kill-line ⌫ delete-backward-char ⌫w backward-kill-word |⌫ kill-line-backward copy kill-ring-save ✂ kill-region (cut) paste yank paste↑ yank-pop (paste previous) M-x execute-extended-command |
1 del win del ohter win |
2 split win horz split win vert |
3 |
4 |
5 qry rep rex qry rep |
6 |
7 |
8 |
9 |
0 |
[ |
] |
Backspace |
' fill/unfill ¶ |
, shrink spaces |
. ⌫w |
p ⌦w |
y |
f |
g ←¶ ←w |
c ▲ ↑ |
r →¶ →w |
l recenter |
/ |
= |
\ |
a shell cmd M-x |
o prev pane next pane |
e ⌫ |
u ⌦ |
i |⌫ ⌦| |
d →| |← |
h |◀ ← |
t ▼ ↓ |
n ▶| → |
s isearch← isearch→ |
- cmt dwim |
Enter |
|
; redo undo |
q ✂ |
j copy |
k paste↑ paste |
x |
b |
m |
w |
v |
z toggle case |
|||
Alt |
Space mark-paragraph set-mark-command |
|||||||||||
Layout shown in png: ergonomic_emacs_layout_dvorak.png.
Here's the emacs lisp file for the above ergonomic keybinding design. ergonomic_keybinding_dvorak.el and ergonomic_keybinding_qwerty.el. Please send your comments or suggestions.
The following table shows commands that will no longer having a shortcut after using the qwerty or dvorak ergomap. If you need them, you will need to bind them.
| M-‹key› Commnands | Ergomap Qwerty | Ergomap Dvorak |
|---|---|---|
| Cursor or Screen Moving | ||
| backward-sentence (M-a) | ✗ | ✗ |
| forward-sentence (M-e) | ✗ | ✗ |
| move-to-window-line (M-r) | ✗ | ✗ |
| center-line (M-s) | ✗ | ✗ |
| Text Deleting | ||
| kill-sentence (M-k) | ✗ | ✗ |
| zap-to-char (M-z) | ✗ | remains |
| Text Transformation | ||
| indent-new-comment-line (M-j) | ✗ | ✗ |
| transpose-words (M-t) | remains | ✗ |
| Other | ||
| facemenu prefix (M-g) | ✗ | ✗ |
| eval-expression (M-:) | ✗ | ✗ |
| abbrev-prefix-mark (M--) | remains | ✗ |
| tmm-menubar (M-') | ✗ | ✗ |
| find-tag (M-.) | remains | ✗ |
| tags-loop-continue (M-,) | remains | ✗ |
| tab-to-tab-stop (M-i) | ✗ | ✗ |
| dabbrev-expand (M-/) | ✗ | remains |
For convenience, the following shortcuts are also made available in this ergo map:
| Standard name | Key press | Elisp command |
|---|---|---|
| Open New File | Ctrl+n | new-empty-buffer |
| Open | Ctrl+o | find-file |
| Close | Ctrl+w | close-current-buffer |
| Save | Ctrl+s | save-buffer |
| Save As | Ctrl+Shift+s | write-file |
| Ctrl+p | print-buffer | |
| Select All | Ctrl+a | mark-whole-buffer |
| Standard name | Key press | Elisp command |
|---|---|---|
| Next Window | Alt+` | next-frame-command |
| Previous Window | Alt+Shift+` (Alt+~) | previous-frame-command |
| Next Tab | Ctrl+→ | next-user-buffer |
| Previous Tab | Ctrl+← | previous-user-buffer |
| - | Ctrl+Shift+→ | next-emacs-buffer |
| - | Ctrl+Shift+← | previous-emacs-buffer |
For convenience, some new commands are added in this lisp code.
| Elisp Command | Description |
|---|---|
| shrink-whitespaces | Calls either just-one-space or delete-blank-lines depending on context. |
| compact-uncompact-block | Calls either fill-paragraph or unfill-paragraph depending on context. |
| toggle-letter-case | Toggles letter case of current word or region. It combines capitalize-word, downcase-word, upcase-word and the -region versions. |
| move-cursor-next-pane | This is the same as other-window. |
| move-cursor-previous-pane | This is the same as (other-window -1). |
Most default shortcuts in the Ctrl+‹key› space are removed. If you wish them to be still available, you can uncomment the code in the elisp file.
Note that the ergo keybindings may not be available with some unusual mode (such as calc), because the calc mode hardwire emacs default keybindings.
On Mac OS X, “Cmd+h” is Hide and “Cmd+Shift+q” is Log Out. If your Meta is Cmd, then the Mac behavior will not be available because the ergo map uses these keys. If you wish to have the Mac behavior, put the following in your “.emacs”:
(setq mac-pass-command-to-system t)
On Microsoft Windows, Right Alt + Right Shift may switch your keyboard layout. You can disable this or change the shortcut to something else in Windows Control panel.
Many modes define their own keybindings. When a mode's special bindings conflict with ones in your global keymap, it'll override it. Vast majority of modes do not use the “M-‹key›” space. (most mode-specific bindings happen in the “C-c C-‹key›” space by convention.)
The ergomap elisp files work with all major language's modes. However, if you downloaded some new mode off the net, you may need to reclaim some keybinding it might have redefined in the M-‹key› space. See: How To Reclaim Keybindings.
On the subject of keyboarding ergonomics, a user may wonder whether switching from QWERTY to Dvorak provides a better improvement than switching from a lousy to better keyboard shortcut layout. (Assuming that he does only one of the above.)
Of my Emacs Commands Frequency study, 37% of key strokes involves data entry (that is, calling the commands “self-insert-command” and “newline” (pressing return), while the rest 63% are calling all other commands. This seems counter-intuitive, because one might think typing should probably be the bulk of activity and moving cursor and deleting text or other commands are only done few times per minute.
If we consider commands invoked by the Backspace key as data entry too, then 40% are data entry, while 60% are editing commands. Still surprising. Going one step further, if we consider the next group of most used commands of moving the cursor by the smallest unit (i.e. previous-line (C-p), next-line (C-n), backward-char (C-b), forward-char (C-f) (also invoked by the arrow keys)) as part of data entry, then, 64% are “data entry” and 36% are other command calls.
This data suggests that better shortcut placement is more important than better placement of letter keys for programing.
See Testimonial for Ergonomic Keybinding.
To comment, please send me email or post to newsgroup gnu.emacs.help↗, comp.emacs↗, or use this blog page: http://xah-lee.blogspot.com/2008/07/ergonomic-keybinding-for-emacs.html.
Support documents:
General reference on emacs's keybinding:
The use of Shift key in emacs keybindings:
General info about common shortcuts, modifier keys, Dvorak layout.
