Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

So I have an IBM Thinkpad X31, running natty and xmonad as the window manager. The keyboard is Italian. I wish to use an American English keyboard mapping, all the time. How do I do this?

share|improve this question

Here is one way to connect XMonad and multiple keyboard layouts.

Step 1. Create a script that will switch between your layouts. For the sake of example, let's say we will support English (US), Italian and French.


# switch between my layouts

# If an explicit layout is provided as an argument, use it. Otherwise, select the next layout from
# the set [us, it, fr].
if [[ -n "$1" ]]; then
    setxkbmap $1
    layout=$(setxkbmap -query | awk 'END{print $2}')
    case $layout in
                setxkbmap it
                setxkbmap fr
                setxkbmap us

Test this script - run it and see if the keyboard layout cycles between the layouts. If it does, proceed to the next step.

Step 2. Customize XMonad settings to support custom key binding that will switch the layout.

In your home directory, create a directory named ".xmonad" (if it does not exist).


import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeys)
import System.IO

main = do
  xmonad $ defaultConfig
        terminal = "gnome-terminal"
     } `additionalKeys`
     [ (( mod1Mask             , xK_Escape), spawn "/home/you/bin/")

Now, restart XMonad by pressing Mod+q. Your layout switcher should be fully functional.


share|improve this answer
This works fine, but restarting XMonad was not enough, I had to logout and in (I am on Ubuntu, with its login manager). – Gauthier Oct 15 '14 at 7:59
the .sh script works for me but shows "[[: not found" – ivan_a Oct 3 '15 at 17:57
nevermind, I was executing it sh running ./ works without any message. – ivan_a Oct 3 '15 at 17:59

To change your keyboard mapping to American English, you run the command setxkbmap us. To integrate it with Xmonad, you add it to the startup hook.

share|improve this answer

You might already have a startup file to launch and configure things at login.

Add the following line to use several keyboard layouts:

# Keyboard layout switcher
setxkbmap -layout us,se -variant ,kinesis -option 'grp:alt_shift_toggle'

-layout and -variant work together. Here my layouts are us (no variant, empty before the comma), and se(kinesis). Variants could be dvorak, for example. You can omit variant if you don't want them.

-option sets here the keyboard shortcut to switch between layouts.

For windows to remember their layout:

# Per window keyboard layout

If you use xmobar and want to show the current layout, add this to your .xmobarrc Config:

, commands = [...
, Run Kbd [("se", "SE"), ("us", "US")]
, template = "...... %kbd% "

That was for all people googling for multiple keyboard layouts and finding this thread. If you want only one keyboard layout, add this to your startup script:

setxkbmap -layout us
share|improve this answer
Works like a charm :) – Heinrich Ody Jan 12 at 16:09

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.