2011-10-16, Sun

How to remap your capslock key to esc key in ubuntu linux

For all vi/vim users out there, here’s how you can remap the CAPSLOCK key and replace it with the ESC key in your linux Xwindows environment.

First Add the following lines of text to your ~/.Xmodmap file1:

    !! No Caps Lock
    clear lock
    !! Make Caps_lock an escape key.
    keycode 0x42 = Escape

Second In your terminal, type the following command:

    xmodmap ~/.Xmodmap

Your CAPSLOCK key is now remapped to the ESC key.

XWindows loads the ~/.Xmodmap file every time it starts, so you won’t have to keep typing the second command.

If you plug/unplug your USB keyboard, or dock/undock your laptop, XWindows may “forget” that mapping. You may need to repeat the second step in a terminal to restore the key mapping functionality.

I’ve tested it in Ubuntu, but it should work just the same for Fedora, RedHat, CentOS, Debian, openSUSE and pretty much anything that runs XWindows.

1 ~/ stands for your home folder. For example, if I type cd ~/ in my terminal, it takes me to /home/isaac/

Isaac Su

tags: capslock esc escape fedora key keyboard linux ubuntu vi vim xmodmap xwindows



  1. thanks a lot for the awesome tip!!

    Abhishek Srivastava · Apr 11, 05:22 AM · #

  2. I am trying to do something similar with Ubuntu. I a trying to remap the page forward and page backward buttons to be used as volume up and down (i accidentally hit them alot because the keyboard on my lenovo isn’t spaced very conveniently) and i’d rather they be used for volume. The trouble is, the buttons currently used for volume on my lenovo aren’t part of the standard keyborad buttons, they’re special buttons that don’t provide a code when I use the “xev” command in terminal. In place of a code that is used to then re-map the function of the button to a different button, terminal spits out a bunch of binary that is unusable.

    Since you seem to be far more experienced than I at this, is there any way for me to re-map the keys I want to?

    If you could respond in an email that would be much appreciated. if you don’t know how to assist me, that is fine as well.

    — Gshaq Goulash · Dec 19, 11:42 AM · #

  3. I can confirm that this tip is still working in 2013 with Ubuntu 13.10 and Unity. Worked really well, in fact. I’m not sure if it will persist, but I can probably write a startup script to make it do so if need be.

    It’s cool that it’s so easy to do this natively on Linux. On Mac OS X, I need to install a program and restart my computer. Linux? 4-line file and reload xmodmap :D

    Kevin Kaland · Mar 10, 11:39 AM · #

Commenting is closed for this article.