Ergoemacs Keybindings

Xah Lee, 2007-07, ..., 2009-01

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 emacs package that makes your emacs use a new shortcut set. This shortcut set is designed based on ergonomic principles, using emacs command call statistics, similar to how Dvorak layout is designed.

Note: This project is mirrored on Google Code, at http://code.google.com/p/ergoemacs/.

Design Basis

Here's the outline of how this design is arrived.

Statistics of emacs commands are compiled from emacs users, and are listed by frequency of use. The top about 30 ones, are given a keyboard shortcut.

To assign the key position, the following rules are used. The rules are listed roughly in order of priority:

  1. Home row keys are the best.
  2. 2nd and 3rd fingers (pointing finger and index finger) are better than 4th (ring finger) and 5th finger (pinky).
  3. The row above home row is considered better than the row below home row. (extending fingers is slightly more comfortable than curling into a fist)
  4. Right hand's keys are considered better than left hand's keys. (because most people are right handed)
  5. Alt is considered better than Ctrl. (Alt is a natural thumb curl, Ctrl is stretched pinky. Thumb is most powerful finger, pinkie the weakest)
  6. In general, cursor moving commands are placed all for the right hand, while text changing commands are all placed for the left hand. (similar to Dvorak having all vowels in one side)
  7. Similar commands should be grouped together to avoid scattering. For example, cursor moving by single char is together (I J K L). Undo, Cut, Copy, Paste are together (Z X C V). Delete char/word left/right are together (E R D F).
  8. Commands with logical reversal or extension are done with Shift key, after other priorities are considered. Examples: Undo/Redo, move cursor to previous/next pane, find replace by string/regex, isearch forward/backward, move cursor by beginning/ending of line. Kill line to the right/left.

The design is based on finger positions, not on first letter of command names. The shortcut set is the same for QWERTY and Dvorak. The ease of remembering what commands are on what keys are based on grouping and positioning. For example, cursor movings are all right hand, text changing are all left hand, moving or deleting to the left/right have keys that are place left and right together, and similar for up/down (by screen or to beginning/end of file). Undo, Cut, Copy, Paste are the familiar row Z X C V.

In this design, only the Meta+‹key› space is used. Some Meta-shift is used too. Ctrl+‹key› space is not used except 7 standard keybindings (Open, Close, Save, Save As, Print, Select All). The operation and consistency of emacs are not unaffected.

The Layout

ergonomic emacs layout qwerty
Symbol Meanings
←   backward-char
←w   backward-word
←¶    backward-paragraph
|←   move-beginning-of-line

→   forward-char
→w   forward-word
→¶    forward-paragraph
→|   move-end-of-line

↑    previous-line
↓    next-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
⌦|   kill-line

⌫    delete-backward-char
⌫w   backward-kill-word
|⌫   kill-line-backward

copy   kill-ring-save
✂      kill-region
paste   yank
paste↑  yank-pop

M-x    execute-extended-command

Shown with Dvorak key labels: Ergoemacs Dvorak.

Download

Download at: http://code.google.com/p/ergoemacs/downloads/list.

Misc

Displaced Commands

The following table are commands that are statistically not often used. They no longer have a keyboard shortcut. If you need them, you will need to bind them. (there are a lot empty space now in “Ctrl+‹key›” space.

Displaced Commands
Emacs CommnandsQwertyDvorak
Cursor Moving
backward-sentence (Alt+a)
forward-sentence (Alt+e)
move-to-window-line (Alt+r)
center-line (Alt+s)
Text Changing
kill-sentence (Alt+k)
zap-to-char (Alt+z)
indent-new-comment-line (Alt+j)
transpose-words (Alt+t)remain
Other
facemenu prefix (Alt+g)
eval-expression (Alt+:)
abbrev-prefix-mark (Alt+-)remain
tmm-menubar (Alt+')
find-tag (Alt+.)remain
tags-loop-continue (Alt+,)remain
tab-to-tab-stop (Alt+i)
dabbrev-expand (Alt+/)remain

Most emacs's default shortcuts in the Ctrl+‹key› space are removed for Kicking the Habit. If you wish them to be still available, you can uncomment the code in the elisp file.

Standard Shortcuts and New Commands

For convenience, the following standard shortcuts are also made available:

Standard Shortcuts
Standard nameKey pressEmacs command name
Open New FileCtrl+nnew-empty-buffer
OpenCtrl+ofind-file
CloseCtrl+wclose-current-buffer
SaveCtrl+ssave-buffer
Save AsCtrl+Shift+swrite-file
PrintCtrl+pprint-buffer
Select AllCtrl+amark-whole-buffer

Window-Switching Shortcuts
Standard nameKey pressEmacs command name
Next WindowAlt+`next-frame-command
Previous Window Alt+~previous-frame-command
Next TabCtrl+PageDnnext-user-buffer
Previous TabCtrl+PageUpprevious-user-buffer
-Ctrl+Shift+PageDnnext-emacs-buffer
-Ctrl+Shift+PageUpprevious-emacs-buffer

The following are new commands in ergoemacs. They combine several emacs commands that each has a keyboard shortcut. Now, you have one single command with one single shortcut, that does what you want depending on context.

New Commands
NameDescription
shrink-whitespacesCalls either just-one-space or delete-blank-lines depending on context.
compact-uncompact-blockCalls either fill-paragraph or unfill-paragraph depending on context.
toggle-letter-caseToggles letter case of current word or region. It combines capitalize-word, downcase-word, upcase-word and the -region versions.
move-cursor-next-paneIdentical to “(other-window 1)”
move-cursor-previous-paneIdentical to “(other-window -1)”.

Notes for Windows and Mac

Mac Users

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 ergoemacs uses these keys. If you wish to have the Mac behavior, put the following in your emacs init file:

(setq mac-pass-command-to-system t)

Windows Users

On Microsoft Windows, “Ctrl+Shift” or some other combination may switch your Input Language or Keyboard Layout. You can disable this, or change the shortcut to something else. Go to your Windows Control panel, keyboards, Advanced Key Settings tab, then press the button “Change Key Sequence...”. (This describes Windows Vista, other Window versions are similar.)

How To Reclaim Keybindings

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 “Meta+‹key›” space. (most mode-specific bindings happen in the “Ctrl+c Ctrl+‹key›” space by convention.)

Ergoemacs is tested to work in all major language's modes. (if you find it otherwise, please let me know) If you downloaded some new mode off the net, you may need to reclaim some keybinding. See: How To Reclaim Keybindings.

Better Shortcut Layout vs Better Key Layout

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, 43% of key strokes involves data entry (that is, calling the commands “self-insert-command” (typing) and “newline” (pressing return), while the rest 57% 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.

This data suggests that better shortcut placement is more important than better placement of letter keys for programing.

Adoption Tips

If you are a long time emacs user, you may find it painful to adopt this setup. This difficulty is nothing special. It's the same difficulty when you switching to dvorak after years of qwerty. Basically, it's about changing muscle memory.

For some tips and elisp code for gradual adoption, see: http://code.google.com/p/ergoemacs/wiki/adoption.

Testimonials

See Testimonial for Ergoemacs.

References

2007-07
© 2007 by Xah Lee.