Remapping the Caps Lock Key
Here is a question: when was the last time you used the Caps Lock key on purpose? When was the last time you went “hey, I wish I could type in ALL CAPS ALL THE TIME”! Chances are that unless you are a Nigerian prince in a dire need of a money transfer, your use of Caps Lock is very limited.
In fact, I’m willing to bet that you hit that key by accident much more often, than on purpose. So why not get rid of it. And I don’t mean physically remove it - that’s just stupid. I mean, remap it to something more useful.

Since I’m a vim user, I decided to remap my Caps Lock to the Escape key. This way I can have an easily accessible Esc under my pinky. This way switching back to normal mode is just single movement. I don’t have to lift my left hand from the home row to hit the actual Esc, and I don’t have to do a two hand motion to use the Ctrl+[ equivalent. Here is how you do it.
First open up your ~/.Xmodmap file and add the following lines:
remove Lock = Caps_Lock keysym Caps_Lock = Escape
Then activate your changes by doing:
xmodmap ~/.Xmodmap
If you want to map Caps Lock to a different key, simply replace Ecape in the sample above with something else like:
- Control_L or Control_R for either left or right Ctrl key
- Alt_L or Alt_R for Alt or AltGr keys
- Super_L or Super_R for the respective “Windows Logo” keys
- Shift_L or Shift_R for respective shift keys
Assigning it to AltGr is also an attractive idea for me, since the Caps Lock position is a bit more accessible than the usual AltGr which I use for typing Polish accented letters. I don’t really see what would be the point of mapping it to Shift, but hey - maybe someone will find that useful.
You can find the rest of key mappings by using the xev utility. Just run it, and start pressing letters and you will see key codes and names for your keys. You can use the same technique to remap almost every single key on the keyboard to whatever you like.
Related Posts:

August 2nd, 2007 at 2:01 pm (5499) [Quote]
Yeah, I keep hitting caps-lock all the time. Mainly because some idiot decided it would be better to move the control key way at the bottom and put put the least used key next to the a key.
Thanks for the tip. I never got around to research this. I guess you saved me a few minutes.
Posted usingAugust 2nd, 2007 at 3:06 pm (5500) [Quote]
Hehe. I still can’t get used to Unix keyboards with the Ctrl in the “correct” place. I know that having it right on the home row level makes it more accessible… But the old habits die hard.
I’m sure it’s the same the other way around too.
Posted usingAugust 2nd, 2007 at 4:15 pm (5501) [Quote]
Well, us “old timers” started typing back before computers had lower case. The control key was ALWAYS next the a key until IBM PCs came out. Since IBM was the “bully on the playground”, everyone changed. I remember my Apple //e Enhanced had the PC layout when I bought it. It caused so much frustration that I bought an aftermarket keyboard to replace it! I now keep a box full of UNIX keyboards. I should be set until the USB standard is obsolete.
Posted usingAugust 2nd, 2007 at 4:23 pm (5502) [Quote]
I have about five of these lying around. I am glad people at my work like the PC style!
Posted usingLINKY
August 2nd, 2007 at 4:59 pm (5505) [Quote]
Oh! We had the same exact keyboard on the SPARC’s at my university. Then I was forced to use one of those when I spilled soda on the shiny new keyboard from the JDS machine.
I could never get the side row buttons to do anything interesting (you know, the copy, paste, hold etc) under Linux.
Posted usingAugust 5th, 2007 at 2:14 am (5525) [Quote]
esc wouldn’t be much better then the caplock key because Windows Messenger (and Live Messenger) use esc. to close out of your current window.
Posted using>.
August 14th, 2007 at 10:31 am (5645) [Quote]
Ok. I tried this and put BackSpace there, so there is a BackSpace for each hand. But “my” BackSpace key doesn’t repeat like other keys. I assume there is a way to turn that on?
Posted usingAugust 14th, 2007 at 10:44 am (5646) [Quote]
Try:
Not sure if that will work though. Safer bet is to probably use the keycode which according to xev is 23 for Caps Lock:
xset r 23August 16th, 2007 at 12:53 am (5694) [Quote]
I hit that bastard caps lock key by accident all the time, I’m now thinking about remapping it to a null setting so I can’t wreak so much upper case-ical havoc on myself.
I don’t really have any other key I’d want to put there, maybe a second A key so when I for A and get caps instead I still type what I intended to
Posted usingSeptember 6th, 2007 at 11:25 am (6082) [Quote]
shucks, I was expecting an ‘imap’ sequence, given that you were talking about vim. What if I have my caps lock remapped in the rest of X for something else already? tough luck?
I’ve got mine remapped to Control. Seems like there is no way to specify the Control key by itself with ‘imap’….
Posted usingSeptember 18th, 2007 at 7:47 pm (6227) [Quote]
Frickhen great!
Posted using Unbranded Firefox 2.0.0.6 onSeptember 30th, 2007 at 7:22 pm (6360) [Quote]
hey man, sweet post. quick question. I changed it in unix, but now when I press “Caps Lock” (which is Control) it doesn’t come out of “Control” unless I press it again. This is annoying in its own right. Do you know how to stop that behavior?
Posted usingSeptember 30th, 2007 at 8:07 pm (6361) [Quote]
The remove lock command should actually do it. Make sure you spelled it correctly.
Posted usingDecember 6th, 2007 at 4:27 am (7277) [Quote]
I tried to remap the control key to “apostrophe” like this
xmodmap -e “remove Control = Control_R”
xmodmap -e “keycode 48 = Control_R”
xmodmap -e ‘add Control = Control_R’
xmodmap -e “keycode 109 = apostrophe quotedbl”
xmodmap -p shows
control Control_L (0×25), Control_L (0×42), Control_R (0×30), apostrophe (0×6d)
Posted usingI thought I just removed Control_R. apostrophe entry is fine, why did I get
Control_R(0×30) again ? any ideas ?
December 13th, 2007 at 9:55 am (7354) [Quote]
I successfully remapped Caps_Lock to Shift using the following commands in the terminal:
Posted usingxmodmap -e "remove Lock = Caps_Lock"xmodmap -e "add Shift = Caps_Lock"
You can put the lines between the quotes in your .Xmodmap file to get the same functionality every time you startup, this solution is good for testing it out, as it is gone when you relogin.
March 3rd, 2008 at 10:06 am (8303) [Quote]
Holy crap, thanks for posting this. I’ve been trying to find a solution for about 6 months now and this is the first solution I could get working. You rock.
Posted usingSeptember 28th, 2008 at 6:25 pm (10274) [Quote]
I know this is @n old topic hopefully someone c@n help me out.. @s you c@n see my @ key is ret@rded, luckily I c@n substitute it. Im wondering if someone could w@lk me through how to ch@nge my @ key to my C@pslock key on Windows XP
@ny help would be @ppreci@ted ty
Posted usingSeptember 28th, 2008 at 7:03 pm (10275) [Quote]
@Michelle: try this link - it seems to have several good solutions (including a GUI app you can just download and install).
Posted using