Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to swap the Left Shift and the Left CTRL keys using setxkbmap instead of xmodmap?


I have switched to Fcitx, which works way much better with my keyboard layout and customized keymap than IBus in every respect. I highly recommend it.

share|improve this question
up vote 14 down vote accepted

xmodmap is obsolete; so indeed it should be done with the xkb tools.

The swap you want seems not to be included by default wth X11 files; so you have to write it yourself.

The page http://madduck.net/docs/extending-xkb/ helped me to understand and find a way to do it.

Create a file ~/.xkb/keymap/mykbd where you put the output of setxkbmap, it will be your base keyboard definition; eg:

setxkbmap -print > ~/.xkb/keymap/mykbd

then, create a symbols file to define your key swapping, put it for example in ~/.xkb/symbols/myswap

there, put the following lines:

partial modifier_keys
xkb_symbols "swap_l_shift_ctrl" {
    replace key <LCTL>  { [ Shift_L ] };
    replace key <LFSH> { [ Control_L ] };

then, edit the ~/.xkb/keymap/mykbd file, and change the xkb_symbols line to add


finally, you can load it with xkbcomp -I$HOME/.xkb ~/.xkb/keymap/mykbd $DISPLAY (you cannot use "~" for the -I parameter). It will probably spit a lot of warnings about undefined symbols for some rare keys, but you can ignore them (eg, redirect error to dave: 2> /dev/null).

If you want to be able to easily swap between a normal and your inverted ctrl/shift one; just create under ~/.xkb/keymap/ another file, without the extra "myswap" option, and load it with xkbcomp. You can make two small scripts to load them.

share|improve this answer
Thanks. It does work, but for once. The problem is that I am using an input engine called IBus. Whenever I switched the input method and then back by the key stroke "Ctrl + Space", Left Shift and Left Control are switched back. Any suggestion on how to avoid it. – day Feb 21 '13 at 14:44
mmn, maybe IBus does itself some keyboard redefinitions. try xkbcomp $DISPLAY some.dump after and before calling IBus, and do a diff of the two dumps (those are complete keyboard definition); you will probably see differences. – Pablo Saratxaga Feb 22 '13 at 10:09
Hmm, it does, how annoying. Any idea to get rid of the problem? Notice that the command setxkbmap -option caps:escape works. IBus remembered the swapped keys Esc and Caps_Lock keys But it does not do for the swapped Left Shift and Left Control keys. – day Feb 22 '13 at 17:14
maybe IBus read the keyboard when launched. Try unloading IBus, changing your keyboard, and loading it again. If problem persists, then an IBus specific question should be made (and maybe report a bug; imho it is, IBus should detect keyboard changes and honour them) – Pablo Saratxaga Feb 24 '13 at 7:11
Thanks, Pablo. I reported the bug. – day Feb 28 '13 at 14:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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