Sat 12 May 2007
Mapping CapsLock to Escape in Xorg
Posted by Markus Bertheau under computer , programming[4] Comments
Ok, as I promised, here is how to map CapsLock to Escape in Xorg. This is especially useful for folks who use vim, as CapsLock in on the home row, and Escape is not. Actually escape is that far away that you have to have really long fingers in order to hit escape without moving your hand from its usual position.
Paths and line numbers are given for Ubuntu 7.04 Feisty Fawn, so if you’re on another distribution or another version of Ubuntu, your mileage may vary.
What we’ll do is add an XkbOption to the keyboard configuration files. At first, add the following at the end of /usr/share/X11/xkb/symbols/capslock:
partial hidden modifier_keys
xkb_symbols "escape" {
key <CAPS> { [ Escape ] };
key <ESC> { [ None ] };
};
This defines an option that maps the CAPS and ESC key codes to the Escape and None symbols respectively. If you don’t want to disable the original Escape key, leave the corresponding line out. Now let’s give it an option name: insert the following line to /usr/share/X11/xkb/rules/base, somewhere around line 810, where the other capslock lines are:
caps:escape = +capslock(escape)
Now let’s add that option to the keyboard configuration in /etc/X11/xorg.conf: Find the InputDevice section for the keyboard and add the following line to the section:
Option "XkbOptions" "caps:escape"
Now restart X by logging out and typing Ctrl-Alt-Backspace at the login prompt. That’s it. CapsLock is gone and on its place Escape stood in.
I wasn’t successful in convincing the XKeyboardConfig maintainer Sergej Udaltsov to accept a patch for this, but I attempted only once yet :)
March 5th, 2008 at 19:55
Thank you kindly.
March 13th, 2008 at 18:45
If you’re old fashioned, you can also put this in your ~/.Xmodmap file:
remove Lock = Caps_Lock
keycode 66 = Escape
July 7th, 2010 at 0:18
Addendum: this feature is now available without editing any files in recent distributions. It’s available from the gnome-keyboard-properties dialog as one of the “layout options” (second tab).
February 9th, 2011 at 6:41
This feature is included in debian as “caps:swapescape”
The “gnome-keyboard-properties” only works with gnome, and only works after you log in, and only works on a per-user basis (which may be an advantage)
The relevant line from my xorg.conf file is:
Option “XkbOptions” “compose:lwin,caps:swapescape”