# Configure the Keyboard Layout

Daniel Weibel
Created 8 Jun 2016

For configuring the keyboard on Linux the tool setxkbmap can be used. Files with information about this tool can be found in /usr/share/X11/xkb.

All keyboard layouts and options are listed in /usr/share/X11/xkb/rules/base.lst.

# Change Keyboard Layout

For example, change layout to Swiss German.

setxkbmap 'ch(de)'


# Set Multiple Keyboard Layouts

For example, Swiss German and German.

setxkbmap 'ch(de),de'


The first layout in the list will be activated by default.

# Define Shortcut For Switching Between Keyboard Layouts

For example, Alt-Shift.

setxkbmap -option 'grp:lalt_lshift_toggle'


# Swap “Caps Lock” and “Ctrl” Keys

setxkbmap -option 'ctrl:swapcaps'


Note: the light on the Caps-Lock key might still be activated by the old Caps-Lock key (which now has the Ctrl function).

# Notes

• The settings made by setxkbmap don’t persists across logins.
• Putting the setxkbmap commands in the ~/.bashrc or ~/.bash_profile to make the settings persistent might cause an X error (cannot open display “default display”)
• Another option to make the settings persistent would be to put the commands in ~/.xinitrc, or in another syntax in /etc/X11/xorg.conf.d/00-keyboard.conf. However, this doesn’t work in a consistent and reliable way, because different desktop environments (e.g. Xfce, KDE, GNOME) read these files in different ways on startup.
• A workaround is to put the setxkbmap in a function in ~/.bashrc and to call this function manually.