If you enjoyed this site, please consider donating $3. Any amount is appreciated. Thanks!

ErgoEmacs Keybinding

Xah Lee, 2007-07, ..., 2009-08-20, 2009-09-06

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, based on emacs command call statistics, similar to how Dvorak layout is designed.

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 for 2nd and 3rd fingers, but for 5th finger the row below is better. (extending fingers is slightly more comfortable than curling into a fist. For the pinky, the top row is more difficult to reach.)
  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. (grouping advantage)
  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 affected.

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

Layout image with Dvorak key labels: ErgoEmacs Keybinding Dvorak, and Colemak key labels: ErgoEmacs Keybinding Colemak.

Download

Latest Version

ergoemac-mode minor mode: ergoemacs-keybindings-5.1.zip. (Released on 2009-09-22, tested in emacs 23.1.x.)

If you are on Windows, you can download the ErgoEmacs emacs distribution for Windows. The ErgoEmacs shortcut set is builtin, with lots other added features.

Older Version

Older version, emacs 22 and emacs 23:

These older versions are provided for whatever reasons people might want them. You shouldn't use it unless you have good reasons. The older version is based on global keymap, not a minor mode. The newer version is a minor mode.

Features

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
FindCtrl+fsearch-forward

The command new-empty-buffer (“Ctrl+n”) lets you open any scratch buffer easily. New buffers are named “untitled”, “untitled<2>”, “untitled<3>”, etc.

The new command close-current-buffer (“Ctrl+w”) will prompt you for save when you close a modified buffer. (tech detail)

The following are some new commands that lets you easily switch windows or buffers.

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 that combine the functionality of several similar commands into one. This way, you have one single command with one single shortcut to remember. They do what you want depending on context.

New Commands
NameShortcutDescription
shrink-whitespacesAlt+wCalls either just-one-space or delete-blank-lines depending on context of neighbor text around cursor.
compact-uncompact-blockAlt+qCalls either fill-paragraph, fill-region, or unfill-paragraph, unfill-region, depending on context. (tech detail)
toggle-letter-caseAlt+zToggles letter case of current word or region. It combines capitalize-word, downcase-word, upcase-word, capitalize-region, downcase-region, upcase-region. (tech detail)

Misc

Displaced Commands

The following table are commands that are statistically not often used. They no longer have a keyboard shortcut.

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

If you use these commands often, you can define shortcuts for them. You can now use the “Ctrl+‹key›” space because there are a lot empty space there now. For how to define your own keybindings, see: How to Define Keyboard Shortcuts in Emacs.

Notes for Windows and Mac

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. Window XP and Windows 7 should be similar.)

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)

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, or switching to Mac after years of Windows. Basically, it's about changing muscle memory.

where-is-old-binding

The ergonomic-mode minor mode features the command where-is-old-binding, with shortcut “Ctrl+h o”. This command asks you to type a shortcut, and tells you what command it was bound in emacs default, and the new shortcut for it under ErgoEmacs.

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

Better Shortcut Layout vs Better Key Layout

On the subject of keyboarding ergonomics, you may wonder if switching from QWERTY to Dvorak provides a better improvement than switching from a lousy to better keyboard shortcut layout. (suppose you chose only one.)

Of my Emacs Commands Frequency study, 43% of key strokes involves data entry (that is, typing and pressing return), while the rest 57% are calling all other commands (moving cursor, deleting chars/words/sentences, formatting, and any emacs command that is not plain typing). 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, in editing tasks for programing, a better shortcut placement is probably more important than better placement of letter keys.

Questions, Discussion, Testimonials

For any questions, suggestions, discussions, or announcement of new version, please post or subscribe at http://groups.google.com/group/ergoemacs.

For defect report, enhancement suggestions, please post a issue at http://code.google.com/p/ergoemacs/issues/list.

For some online news mentions and testimonial, see: Testimonial for ErgoEmacs Keybinding.

Acknowledgement

Much thanks to David Capello, who made this package into a full-featured minor-mode starting with version 5.0.0. (2009-09).

Thanks to many other people who helped in code snippets or suggestions. Please see the package's header for a full list.

References

2007-07
© 2007 by Xah Lee.