Linux + Xorg : Remapping caps lock key to escape

In this post I’ll revisit the classical “how to remap caps lock into something useful” once again. In this post, I’ll show how to remap the caps lock key to have an extra Escape key, which is very useful for all VI/Vim users.

Method 1 : Using xmodmap

This is mostly the usual way of altering the keyboard map. All you have to do edit the ${HOME}/.Xmodmap file like below :

clear Lock
keycode 66 = Escape

This file is often sourced when your X sessions is opened, but there are numerous bug reports stating that it’s either ignored or overridden by some windows managers.

You might need to source the file by running xmodmap ~/.Xmodmap at some point after the windows manager is started.

Method 2 : Using XKB configuration

If you let Xorg setup your keyboard by consulting HAL, you can remap the caps lock key to escape by having the following policy file in /etc/hal/fdi/policy/keyboard.fdi

<?xml version="1.0" encoding="UTF-8"?>
<deviceinfo version="0.2">
        <device>
        <match key="info.capabilities" contains="input.keyboard">
                <match key="info.product" contains="Logitech Logitech USB Keyboard">
                        <merge key="input.x11_driver" type="string">evdev</merge>
                        <merge key="input.x11_options.XkbOptions" type="string">caps:escape</merge>
                        <merge key="input.x11_options.XkbLayout" type="string">us</merge>
                        <merge key="input.x11_options.XkbVariant" type="string">intl</merge>
                </match>
        </match>
        </device>
</deviceinfo>

The caps:escape takes care of setting up caps lock as an escape key.

See more about How to setup Xorg according to HAL

If you don’t use HAL and prefer to setup your keyboard through xorg.conf, it will look like the snippet below :

Section "InputDevice"
    Identifier "Keyboard1"
    Driver "evdev"
 
    Option "XkbLayout" "us"
    Option "XkbVarian" "intl"
    Option "XKbOptions" "caps:escape"
EndSection

To see the other available options, check /usr/share/X11/xkb/rules/xorg

Further readings :

Leave a Reply

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