Keyboard issues

Home : Emacs tips : Keyboard


If you plan on using emacs extensively in the future, you should put some time into learning to touch-type emacs. There are several important advantages:

  1. Using the keyboard effectively will improve your productivity greatly.
  2. Not using the keyboard awkwardly will help avoid hurting your hands.
By "touch-type emacs," I mean being able to type commands without looking at the keyboard by using the fingers of the appropriate hand to type the character, and those of the other hand (preferably the stronger index and middle fingers) for the "Control" and "Meta" shifts.

Table of contents

  1. Keyboard issues
    1. Table of contents
    2. Recommended keyboard reconfiguration
    3. X11 Keyboard reprogramming with xmodmap
    4. The "Super-" shift
    5. xmodmap and Sun keyboards
    6. xmodmap and PC keyboards
    7. An extreme suggestion

Recommended keyboard reconfiguration

In order to touch-type emacs commands, it is necessary to configure your keyboard with a "Control" modifier key and a "Meta" modifier key on each side of the keyboard. Such things as C-M-t are just plain awkward to type if you have to use the same hand for the "Control" and the "T" keys. If you get into the habit of typing control/meta modifiers with the opposite hand from the character key, you will be able to rip out those commands faster with less wear and tear on your hands.

Carpal tunnel syndrome is not conducive to productivity, and I suspect that the contortions that are otherwise necessary to type arcane key combinations are a factor. Some people mistakenly blame these contortions on emacs, when the problem is really due to brain-dead keyboard layouts; some hardware manufacturers must assume that you will hardly ever want to type modifier keys. Many old Hewlett-Packard keyboards had a single tiny "Ctrl" key at the extreme upper-left of the main key layout; furthermore, of all the keys, "Ctrl" was the only one that was hardwired and therefore incapable of being moved by software to a reasonable location.

Fortunately, despite being made for computers with operating systems that are more mouse- than keyboard-oriented, most recent keyboards include a selection of modifier keys, symmetrically placed around the space bar. Unfortunately, both Mac and PC systems put the "Control" keys at the extreme ends of the row, which is hard on the pinkies. It is much easier to type modifier keys with the index and middle fingers, and much faster to do so if these keys are near the space bar. Consequently, even "modern" keyboards usually need reprogramming to work well with emacs.

My emacs-friendly keyboard-reprogramming scripts for X11 under Unix are described below. As for non-Unix machines, or X11 running under Windows, you'll need to check the window system documentation.

X11 Keyboard reprogramming with xmodmap

If you are using X11 on a Unix machine, the way to do this is with the xmodmap command. I use

    xmodmap sun4u.xmodmaprc
for Sparcstations, and
    xmodmap i586.xmodmaprc
for my PC; the naming convention allows my .xinitrc script to recognize which is appropriate. Both versions tell xmodmap to change the keyboard layout to roughly the same configuration (allowing for different key sizes) that makes it easy to touch-type emacs. (I picked this configuration to resemble the Lisp Machine keyboards of my youth, which is why the "Control" keys are closest to the space bar and the "Meta" keys just outside of "Control". If this annoys you, or you would rather have something more consistent with PC usage, you can always swap "Control" and "Meta" in the "keycode xx =" assignments.)

If you'd rather not mess with the xmodmap program directly, you can use Jamie Zawinski's xkeycaps program, which provides a Mac-like interface for finding out and changing keyboard configuration information. See also the xkeycaps man page, which summarizes how X11 handles keyboards.

The "Super-" shift

Use of the "Super-" shift is optional. If you like, you can bind keys to "Super-" shifts in emacs by using something like

    (global-set-key [?\s-b] 'beginning-of-line)
But I hardly ever take advantage of this, mostly because these shifts are inconvenient to type. However, even if you have no use for these keys, it still pays to leave them as "Super-" shifts, since this effectively disables the unused keys that send "Super-". Nothing is bound to Super-anything in emacs by default, so if you type "s-x" (Super-x) when you meant "M-x", emacs will just beep; if you had set the key to generate nothing, it would have inserted an "x" (or worse).

xmodmap and Sun keyboards

Specifically, sun4u.xmodmaprc makes the the following changes to the default key interpretations on Sparcstations:

I have used this on Sparcs for which uname -m returns "sun4u" or "sun4m"; use with caution on older Sparc keyboards. Do not use this on non-Sparc machines; it will probably screw up your keyboard, since the keycodes will almost certainly be different.

If you want a more PC-compatible configuration, you can leave "Meta" where it is and put "Control" on "Caps Lock" and "Alt Graph". You will then be typing "M-" with your index fingers, and "C-" with your middle fingers.

xmodmap and PC keyboards

The i586.xmodmaprc file makes the following changes to the default key interpretations for XFree86 on my GNU/Linux PC:

Graphically, the bottom row of the keyboard changes from this:

    +-----++----++----++---------------------------++----++----++----++-----+
    |Ctrl ||Flag||Alt ||         Space bar         ||Alt ||Flag||Menu||Ctrl |
    +-----++----++----++---------------------------++----++----++----++-----+
to this:
    +-----++----++----++---------------------------++----++----++----++-----+
    |Super||Meta||Ctrl||         Space bar         ||<no>||Ctrl||Meta||Super|
    +-----++----++----++---------------------------++----++----++----++-----+

This is inconsistent from right to left, but it more accurately echoes the physical arrangement I have set up on the Sun Sparcstation keyboards at work. Please read the comments in the file before you attempt to use it. Do not use this on non-PCs; it will probably screw up your keyboard, since the keycodes will almost certainly be different.

An extreme suggestion

If I were willing to reprogram my brain (again) in order to take advantage of a more emacs-optimal keyboard layout, I'd probably do a few things differently. In particular, I'd keep the "Meta-" keys next to the space bar, so that people with no Lisp Machine experience don't freak out when the try to type on my keyboard. Better still, since it is most efficient to avoid switching hands during command sequences that bounce back and forth from one side of the keyboard to the other (how fast can you type "C-p C-a C-o C-b"), I might try using the "Super-" shift to overload the left half of the keyboard. In other words, That way, I could type long command sequences with the left hand in standard position, and the three longest fingers of the right hand providing all of the modifier shifts. I would only ever have to move my right hand, and only to type long sequences of text.

Then again, if I were willing to reprogram my brain at all, I'd be better off switching to an ergonomic split-keyboard design that puts the modifiers in the middle where they can be worked with the thumbs without ever needing to move your hands.


Bob Rogers <rogers@rgrjr.dyndns.org>
Last modified: Sun May 28 19:40:39 EDT 2000