How to get umlauts via AltGr using Debian and xkb

Or: "domm vs umlaut 1:0"

Even though I'm a German native speaker I prefer to type on a QWERTY keyboard. Most of my writing is source code, so I like to have easy access to the various brackets and special characters. Which isn't working on a German QWERTZ keyboard. But not all my writing is source code, and some is even in German, therefor I need to type umlaute from time to time.

I used to map stuff like ü to AltGr-u using xmodmap and something like keycode 30 = u U udiaeresis Udiaeresis. But this stopped working in recent Debian, because apparently xmodmap has been superseded by xkb. At least after an update AltGr-u would produce õ instead of ü.

After a lot of RTFMing, I figured out how to add some custom mappings to a so-called symbols file. I took the easy route and just copied the us file from /usr/share/X11/xkb/symbols/us to /usr/share/X11/xkb/symbols/domm and altered a few lines:

 key <AD07> { [ u, U, udiaeresis, Udiaeresis ] };
  key <AD09> { [ o, O, odiaeresis, Odiaeresis ] };

I loaded the new mapping using setxkbmap domm but I still got the dreaded õ.

I kept trying to fix this for a few months, but never got it working, which was rather depressing. Also, I had to resolve to very annoying workarounds if I needed an Umlaut (like switching to a German keyboard layout and trying to remember which Umlaut was where; going to this page and copy'n'paste the damn letter; having MaKo type the letter in our IRC channel, and copy it from there...)

But yesterday I gave it another shot, and I figured it out!! I don't exactly remember the steps I took (because it was 1:30 in the morning..), and I still have not the slightest idea why AltGr-u produced õ, but the secret was to tell xkb to use the Right Alt Key (aka AltGr) as a Level 3 Switch:

setxkbmap domm -option lv3:ralt_switch

These were among the hardest 23 characters I've ever learned...

My complete setxkbmap command (loaded via @.xinitrc) is:

setxkbmap domm -option lv3:ralt_switch -option ctrl:nocaps

ctrl:nocaps turns off CAPS-LOCK (the most useless key on any keyboard) and replaces it with CTRL.

And now, I proudly present: üÜäÄöÖ߀