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.

No More Caps Lock

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. :mrgreen:

[tags]keymap, key mapping, remapping keys, caps lock, remapping caps lock, escape, caps lock to escape, esc[/tags]

This entry was posted in Uncategorized. Bookmark the permalink.



29 Responses to Remapping the Caps Lock Key

  1. Craig Betts UNITED STATES Mozilla Firefox Solaris Terminalist says:

    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.

    Reply  |  Quote
  2. Luke UNITED STATES Mozilla Firefox Ubuntu Linux says:

    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.

    Reply  |  Quote
  3. Craig Betts UNITED STATES Mozilla Firefox Solaris Terminalist says:

    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.

    Reply  |  Quote
  4. Craig Betts UNITED STATES Mozilla Firefox Solaris Terminalist says:

    I have about five of these lying around. I am glad people at my work like the PC style!
    LINKY

    Reply  |  Quote
  5. Luke UNITED STATES Mozilla Firefox Ubuntu Linux says:

    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. :P

    Reply  |  Quote
  6. 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.
    >.

    Reply  |  Quote
  7. Don UNITED STATES Mozilla Firefox Linux says:

    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?

    Reply  |  Quote
  8. Luke UNITED STATES Mozilla Firefox Ubuntu Linux says:

    Try:

    xset r Caps_Lock

    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 23
    Reply  |  Quote
  9. Matt` UNITED KINGDOM Mozilla Firefox Windows Terminalist says:

    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

    Reply  |  Quote
  10. Jeff SINGAPORE Mozilla Firefox Ubuntu Linux says:

    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’….

    Reply  |  Quote
  11. Albert SWITZERLAND Mozilla Firefox Linux says:

    Frickhen great!

    Reply  |  Quote
  12. Tom UNITED STATES Mozilla Firefox Windows says:

    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?

    Reply  |  Quote
  13. Luke Maciak UNITED STATES Mozilla Firefox Windows says:

    The remove lock command should actually do it. Make sure you spelled it correctly. :)

    Reply  |  Quote
  14. sanjeev INDIA Mozilla Firefox Ubuntu Linux says:

    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 (0x25), Control_L (0x42), Control_R (0x30), apostrophe (0x6d)
    I thought I just removed Control_R. apostrophe entry is fine, why did I get
    Control_R(0x30) again ? any ideas ?

    Reply  |  Quote
  15. Ian UNITED STATES Mozilla Firefox Windows says:

    I successfully remapped Caps_Lock to Shift using the following commands in the terminal:
    xmodmap -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.

    Reply  |  Quote
  16. James UNITED STATES Opera Linux says:

    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.

    Reply  |  Quote
  17. Michelle CANADA Mozilla Firefox Windows says:

    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 :x @ny help would be @ppreci@ted ty

    Reply  |  Quote
  18. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

    @Michelle: try this link – it seems to have several good solutions (including a GUI app you can just download and install).

    Reply  |  Quote
  19. nitro2k01 SWEDEN Mozilla Firefox Linux Terminalist says:

    Thank you for the xset r comment! My laptop has broken enter and up arrow keys, which I have replaced with rctrl and rshift. However, these keys did not repeat, and xset r solved that problem. Thus I ended up doing this which solved my problem completely.xmodmap -e "remove shift = Shift_R"
    xmodmap -e "keycode 62 = KP_Up KP_Up KP_Up KP_Up KP_Up"
    xmodmap -e "remove control = Control_R"
    xmodmap -e "keycode 105 = KP_Enter NoSymbol KP_Enter NoSymbol KP_Enter"
    xset r 62
    xset r 105

    Reply  |  Quote
  20. FreshCode Google Chrome Windows says:

    I wrote a portable app to Remap Caps Lock to Backspace without rebooting. Now I can type on your keyboard. Download the free 3.50KB executable and the source from the link.

    Reply  |  Quote
  21. nitro2k01 SWEDEN Mozilla Firefox Mac OS Terminalist says:

    Hey, FreshCode, I can’t run that binary, even if I do chmod +x on it. I tried recompiling it from source code too, but it wouldn’t compile. :/

    Reply  |  Quote
  22. nitro2k01 SWEDEN Mozilla Firefox Mac OS Terminalist says:

    Hmmm, seems like WP nomnomnom’d the </sarcasm> tag… (Rewrote the tag characters with HTML entities for this post, which worked.)

    Reply  |  Quote
  23. FreshCode Google Chrome Windows says:

    @nitro2k01, what OS are you on? It sounds like you’re on a Linux box. What compiler did you use, gcc? The source code was built in a Microsoft environment and is meant for Windows.

    Reply  |  Quote
  24. nitro2k01 SWEDEN Mozilla Firefox Mac OS Terminalist says:

    Well, the next comment by me is mentioning a missing </sarcasm> tag, so go figure… I was mostly commenting the irony that you’re advertising a Windows tool on a blog post about how to remap caps lock on Linux. One might think that you didn’t even read the post before commenting. ;)

    Reply  |  Quote
  25. FreshCode Google Chrome Windows says:

    @nitro2k01: It’s easy to remap Caps Lock in most Linux distro’s. If you are used to it and ever need to work on a Windows box (which dominates the desktop market), then remapping becomes a chore. I’ve added to my post that it is meant for Windows, but step back for a bit and realise: touch typing is cross-platform compatible :).

    Reply  |  Quote
  26. nitro2k01 SWEDEN Mozilla Firefox Mac OS Terminalist says:

    *zzzip*
    Did you hear that? That was the point of my comment that went right above your head. My whole point is that you’re a “spammer” who’s out hunting for SEO and that you probably didn’t even read the post that you left a comment to.

    Reply  |  Quote
  27. FreshCode Google Chrome Windows says:

    @nitro2k01, you win. I’m a spammer who doesn’t read and didn’t write an app to solve a legitimate problem I had related to this post on Windows </flamewar>
    @Luke, sorry about the noise.

    Reply  |  Quote
  28. nitro2k01 SWEDEN Mozilla Firefox Mac OS Terminalist says:

    Well, in a few days when Google have rerun their index we’ll see how much of a spammer you are or aren’t. Until then, have a good day, or something. You even apologized for the noise. Good, good…

    Reply  |  Quote
  29. peter AUSTRALIA Mozilla Firefox Ubuntu Linux says:

    nice post! i have set up a fb group called “society for the abolition of capital letters” and used your jpg – i hope you dont mind! if you want me to take it down just let me know and i can remove it straight away :) also feel free to join my group if you like…

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *