How to re-enable the caps lock key

keyboard-layoutx11xkbxmodmap

I am currently setting up my default keyboard layout like this:

setxkbmap -layout us -variant dvorak -option ctrl:nocaps,[...]

It disables the caps lock key and makes it an additional ctrl key, along with a swarm of other options.

I would like to do the following to switch keyboard layouts:

setxkbmap -layout us -variant dvorak-l -option ctrl:swapcaps

However, it does not re-enable the caps lock key; both the left control key and the caps lock stay as control keys as far as I can see.

I know I can clear the whole options list, but in the interest of maintainability, I would rather not copypaste the options around. How do I re-enable caps lock?

Update:
Looking at keypresses with xev(1), it appears ctrl:nocaps gives a Control_L for both keys, and ctrl:swapcaps "restores" the caps lock key (pressing the key gives Caps_Lock). However, the caps lock LED does not light up nor does it actually work.

Looking at the xkeyboard-config/symbols/ctrl file in X.org sources does hint at the problem:

xkb_symbols "nocaps" {
    replace key <CAPS>  {  [ Control_L, Control_L ] };
    modifier_map  Control { <CAPS>, <LCTL> };
};
xkb_symbols "swapcaps" {
    replace key <CAPS>  {  [ Control_L ] };
    replace key <LCTL>  {  [ Caps_Lock ] };
};

The latter option lacks a modifier_map line, whatever that does

Best Answer

The following commands should work:

xmodmap -e 'keycode 0x42 = Caps_Lock'

or

setxkbmap -option

The commands above work just fine to restore the default behaviour, which I hardly ever need, luckily.

I normally remap the capslock to Control (luckily VI/VIM supports CTRL-C instead of ESC) with the following command:

setxkbmap -option ctrl:nocaps -layout gb
Related Question