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

Related Posts:

  • Scroll Lock
  • Bump Keying
  • How do you lock down XP Home?
  • Another 419
  • Joy! Joy! Happy Time! DRM is Dying!
  • MySQL: How to get the key of last inerted row in PHP
  • I got 419′d!!!
  • Teaching GPG to the Masses
  • Please Send Clue to Boston!
  • On Config Files

  • 18 Responses to “Remapping the Caps Lock Key”

    1. Gravatar Craig Betts UNITED STATES Says: Reply to this comment

      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 using Mozilla Firefox Mozilla Firefox 2.0.0.6 on Solaris Solaris
    2. Gravatar Luke UNITED STATES Says: Reply to this comment

      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 using Mozilla Firefox Mozilla Firefox 2.0.0.2 on Ubuntu Linux Ubuntu Linux
    3. Gravatar Craig Betts UNITED STATES Says: Reply to this comment

      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 using Mozilla Firefox Mozilla Firefox 2.0.0.6 on Solaris Solaris
    4. Gravatar Craig Betts UNITED STATES Says: Reply to this comment

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

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.6 on Solaris Solaris
    5. Gravatar Luke UNITED STATES Says: Reply to this comment

      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

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.2 on Ubuntu Linux Ubuntu Linux
    6. Gravatar Travis McCrea UNITED STATES Says: Reply to this comment

      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 Mozilla Firefox Mozilla Firefox 2.0.0.3 on Windows Windows XP
    7. Gravatar Don UNITED STATES Says: Reply to this comment

      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 using Mozilla Firefox Mozilla Firefox 2.0.0.4 on Linux Linux
    8. Gravatar Luke UNITED STATES Says: Reply to this comment

      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
      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.2 on Ubuntu Linux Ubuntu Linux
    9. Gravatar Matt` Says: Reply to this comment

      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 using Mozilla Firefox Mozilla Firefox 2.0.0.6 on Windows Windows XP
    10. Gravatar Jeff SINGAPORE Says: Reply to this comment

      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 using Mozilla Firefox Mozilla Firefox 2.0.0.6 on Ubuntu Linux Ubuntu Linux
    11. Gravatar Albert SWITZERLAND Says: Reply to this comment

      Frickhen great!

      Posted using Unbranded Firefox 2.0.0.6 on Linux Linux
    12. Gravatar Tom UNITED STATES Says: Reply to this comment

      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 using Mozilla Firefox Mozilla Firefox 2.0.0.7 on Windows Windows 2000
    13. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

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

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.7 on Windows Windows XP
    14. Gravatar sanjeev AUSTRALIA Says: Reply to this comment

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

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.6 on Ubuntu Linux Ubuntu Linux
    15. Gravatar Ian UNITED STATES Says: Reply to this comment

      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.

      Posted using Mozilla Firefox Mozilla Firefox 2.0.0.4 on Windows Windows Vista
    16. Gravatar James UNITED STATES Says: Reply to this comment

      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 using Opera Opera 9.22 on Linux Linux
    17. Gravatar Michelle CANADA Says: Reply to this comment

      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

      Posted using Mozilla Firefox Mozilla Firefox 3.0.3 on Windows Windows XP
    18. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

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

      Posted using Mozilla Firefox Mozilla Firefox 3.0.3 on Windows Windows XP

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <pre lang=""> <em> <i> <strike> <strong>

    [Quote selected]