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

  • I'm guessing everyone who tried to help me got their keyboards stuck to dvorak =( – hhaamu Oct 21 '11 at 7:51
  • 4
    X is so old and complex now that not many people really understand the various internal mechanisms. There's even sections in the man page that says (and I quote): "Nobody wants to say how this works. Maybe nobody knows ...". I am interested in seeing an answer to this question as well but it may be the case that nobody knows ... – jw013 Feb 13 '12 at 6:15

The following commands should work:

xmodmap -e 'keycode 0x42 = Caps_Lock'


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
  • The "setxkbmap -option" to clear the settings is exactly what I was looking for. I kept trying to change my behavior, but it kept appending conflicting items to the options list. – m0j0 Jun 13 '15 at 22:55

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

From the manpage:

[...] If you want to
replace all previously specified options, use the -option  flag
with an empty argument first.

Irony is that here -option ctrl:swapcaps actually overrides -option ctrl:nocaps — I guess the behavior changed.

Edit: As the OP stated, he wants to avoid clearing the options (as done in the way above).

/usr/share/X11/xkb/rules/xorg.lst shows the option ctrl:aa_ctrl (control at bottom left), which seems to reset caps lock after nocaps here.

I guess it's worth a try, and you can also look at the list (grep ctrl\:) and see if there's something else which may work, in case this one doesn't.

If there's no option for this, I guess the solution is to hack the current keymap, by associating Caps Lock with the Caps Lock key again (but I don't have experience with that, other than believing there's a tool that allows you to do that with a one-liner).

  • That indeed does clear the options list, but I wish to keep the non-caps-related options (as I stated in the question) such as compose keys. – hhaamu Feb 14 '12 at 9:44
  • Oh, sorry, I misread the question. I can't be sure if this will work (as I stated, swapcaps actually re-enables caps lock here), but from /usr/share/X11/xkb/rules/xorg.lst, I see there is the option ctrl:aa_ctrl (control at bottom left), which seems to reset caps lock after nocaps here. – njsg Feb 14 '12 at 10:49
  • I think the magic program is xmodmap but I'm not quite sure how to use it – hhaamu Feb 19 '12 at 20:14

there is an option "caps:capslock" (that maps to adding "+capslock(capslock)" to xkb_symbols) that enables the capslock.

However, that option (maybe all caps:xxxxx ?) is added before the existing ctrl:xxxxx ones; as ctrl:swapcaps redefine the capslock key, that option has no effect.

So, you absolutely need to remove all options and actually put the ones you want; the way options exist they are not supposed to undo the action of a previous one, and having conflicting options (eg, two (or more) that reefine a same key) you cannot define their ordering.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.