Most of the time I use the US qwerty layout but from time to time I also have to use the German layout which is qwertz and it is very annoying.

How can I swap the y and z keys on the German layout?

The solution was at this link: Custom Keyboard Layout in Ubuntu (or just Linux :) kindly provided by gertvdijk in his answer.

NB: In recent versions of Ubuntu you have to issue sudo dpkg-reconfigure xkb-data for the changes to take effect. See this answer.


This how-to should do the trick for system-wide keyboard remap of single keys: FAQ: How to disable/remap a keyboard key in Linux?

And this how-to is about creating your own custom keymaps: Custom Keyboard Layout in Ubuntu (or just Linux :)

It won't allow you to change it quicky using a shortcut. You'll need some scripting to do so, I guess.

However, from the first revision of your question I assumed you wanted to change layouts. You've revised your question, but here is how to change layouts:

From the tags I assume you're running Kubuntu (KDE) 12.04 changing layouts pretty straightforward:

  1. Open 'System Settings'
  2. Open 'Input Devices'
  3. Select 'Keyboard' on the left vertical tab.
  4. Select 'Layouts' on the horizontal tab.
  5. Tick the checkbox 'Configure layouts'.
  6. Add your preferred keyboard layouts by clickin the 'Add' button and filling in the fields in the dialog. Selecting an English (US) layout will result in 'qwerty'. -- Optionally configure a shortcut key to change layouts quickly.
  7. Click apply.

KDE keyboard configuration dialog

This should cover keyboard layout and behaviour in your user session. For system wide settings including text console, see this question.

  • Yes, that's how I added the German keyboard. But it doesn't answer my question: how do I change the qwertz German keyboard layout to qwerty? – Ali Sep 14 '12 at 21:18
  • @Ali: Adding an English (US) layout and activate it? – gertvdijk Sep 14 '12 at 21:20
  • 1
    Sorry, I don't follow. I am happy with the US layout and when I change to the DE layout the y and the z should be swapped as in the US layout. That is my question. – Ali Sep 14 '12 at 21:22
  • @Ali: Then I don't follow your question. Switching layouts like this works for me. – gertvdijk Sep 14 '12 at 21:24
  • I don't want to switch layout. Given a layout (German) how can I switch the y and the z keys? – Ali Sep 14 '12 at 21:28

It’s very simple. You should edit the German layout file; so open it through a Terminal (Ctrl+Alt+T):

sudo gedit /usr/share/X11/xkb/symbols/de

In the opened file, you can see “z” on the 27th line:

    key <AD06>  { [         z,          Z,    leftarrow,          yen ] };

and “y” on the 38th line:

    key <AB01>  { [         y,          Y,       guillemotright,    U203A   ] };

All you need to do is to switch y’s and z’s. Then save the file and close it.

Log out one time and log in back again to see the result.

  • Sometimes, this change has no effect. Remove *.xkm files in /var/lib/xkb to force the new keymap to recompile. See this link. – janosdivenyi Sep 1 '15 at 8:24
  • @janosdivenyi, in recent versions of Ubuntu, of course. See this answer. – AliN Sep 2 '15 at 20:29
  • I switched AD06 and AB01, restarted computer and all is working fine, thanks for this solution, +1 – x-magix Jul 29 '20 at 11:47

I can now select German (qwerty) in the Unity desktop in 14.04:

enter image description here

This gives me exactly what I want.

It is also possible to switch to this particular layout in the terminal:

setxkbmap -layout de -variant qwerty

There is absolutely no need to mess with the system's keyboard layout files!

  • @mrk Please post it as a new question. It is impossible for me to tell what happened on your system without knowing the details. Don't post it in a comment, post a new question. – Ali Jul 10 '19 at 19:19

To switch the z and y keys in your X (graphical) session, execute the following command in a terminal in the session:

a=52;b=29;c=xmodmap;d="$c -e '";$c -pke | sed -nr "s/^(keycode *)$b(.*)/$d\1$a\2'/p;t;s/^(keycode *)$a(.*)/$d\1$b\2'/p" | sh

  • Works on first,i will see after restart. – Goran_Ilic_Ilke Aug 27 '19 at 13:55

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.