Since I recently "switched religions"---i.e., I use vim now instead of xemacs, I find that I need to hit the escape key quite a bit more frequently for some reason. :-) Now, one of the major advantages of the vi-class editors is that you don't need to move your hands from the home row that often. If you happen to know how to touch-type, then this is a major advantage.
On my keyboard, the escape key is located way at the top. This is inefficient. Insprired by a recent discussion on slashdot, I decided to swap the escape and caps-lock keys. The slashdot people helped get me started by reminding me of xmodmap, but the poster was trying to remove capslock altogether. Acutally, I do use capslock on occasion. (I touchtype....)
I used xev to figure out the keycodes for the keys that I wanted to remap. Just run xev and hit the key you want. When I hit Escape, here's what it printed out:
KeyPress event, serial 29, synthetic NO, window 0x2600001, root 0x4c, subw 0x0, time 1088941543, (43,83), root:(594,518), state 0x0, keycode 9 (keysym 0xff1b, Escape), same_screen YES, XLookupString gives 1 bytes: (1b) " XmbLookupString gives 1 bytes: (1b) " XFilterEvent returns: FalseThe "keycode 9" is the part you want. A similar action shows you that capslock is keycode 66.
Now you are ready to write your .xmodmap file. Here is mine:
remove Lock = Caps_Lock keycode 0x42 = Escape keycode 0x09 = Caps_Lock add Lock = Caps_LockFirst, it removes the "lock" functionality from the capslock key. Then I tell it that key 66 (0x42 is hexadecimal for 66) is now the escape key, and that key 09 (the old escape key) is now capslock. Finally, I add the Lock functionality back to the new capslock.
It works very well. Typing in vim is much faster, since I can switch modes with the same ease that I can shift letters. And if I do decide to use capslock, it is still there, not that far away. Now that I've reprogrammed my keyboard, all I have to do is reprogram my hands....