How I remapped my keyboard to have a better developer experience

Sean Nicholas
6 min readApr 14, 2019

First things first: This post is for linux users only. Sorry, the rest of you. I don’t know if there is a similar thing for mac or windows 🙁.

The Problem

I’m German and have a German keyboard. Which looks like this:

German Keyboard Layout. Attribution: A.Illigen [CC BY-SA 4.0 (https://creativecommons.org/licenses/by-sa/4.0)] from https://commons.wikimedia.org/wiki/File:Tastatur_DE_hellgrau.svg

As you can see the round brackets are on SHIFT + 8 / 9, the curly braces on ALT Gr + 7 / 0 (ALT Gr is a special German key) and for square brackets you need to push ALT Gr + 8 / 9.

The reason for this design is that IBM wanted to cut costs and produce only one type of keyboards, relabeling them for different countries. Because writing text was prioritized over programming the braces got those hard to reach places.

A solution in my head

Luckily the German Keyboard has keys for our famous Umlaute (ö, ü, ä), too. Those aren’t really needed when you code (hopefully you write you comments not in German 😁). Therefore, I thought it would be a great idea to remap those to the braces.

I didn’t want to use an English keyboard mapping because I wanted to keep as much muscle memory as possible and I didn’t liked that you need to push SHIFT to get round & curly braces.

My new coding keyboard design

Here is how I wanted to remapped my keyboard for coding. An image for a quick overview and a short list to make it more accessible.

Remapped keyboard for coding. Adapted from A.Illigen [CC BY-SA 4.0 (https://creativecommons.org/licenses/by-sa/4.0)] (source here: https://commons.wikimedia.org/wiki/File:Tastatur_DE_hellgrau.svg)
  • SHIFT + 8 should point to | (German keyboard: Alt Gr + <)
  • SHIFT + 9 should point to \ (German keyboard: Alt Gr + ß)
  • ü should point to { (German keyboard: Alt Gr + 7)
  • SHIFT + ü should point to } (German keyboard: Alt Gr + 0)
  • ö should point to ( (German keyboard: SHIFT + 8)
  • SHIFT + ö should point to ) (German keyboard: SHIFT + 9)
  • ä should point to [ (German keyboard: Alt Gr + 8)
  • SHIFT + ä should point to ] (German keyboard: Alt Gr + 9)
  • I wanted to switch # and ' because I code lots of JavaScript and need the single line quote much more often than the hashtag
  • Another annoying thing is that the decimal separator in Germany is a comma and in English a full stop. Therefore I replaced the comma on the num pad

Unlike the German or English keyboard, I put the opening and closing braces onto the same key. This is because most modern IDEs close braces automatically. You don’t need to write a closing one that often. Plus it makes the mental model much easier. SHIFT + brace key always equals a closing brace.

Finding the keycodes

First, I needed to find the keycode of the keys I wanted to remap. xev is the right tool for this. After installing you just start it with xev and a little window opens:

xev Event Tester

Focus that window and hit the keys you want to replace. There is quite some information printed into the console. We are searching for the string keycode [YOUR KEYCODE]. Write down that number. In my case it is:

  • keycode 34 for ü
  • keycode 47 for ö
  • keycode 48 for ä

Remapping the keys

Before we can remap the keys we need to know about keysyms. These are code words for the letters we want to print. For example the keysym for { is braceleft . You can find a full list here.

To remap a key you use xmodmap -e . For example. To remap my ä key to ( on a normal press and to ) in combination with SHIFT, I run this line:

xmodmap -e "keycode 47 = parenleft parenright"

Now the key is mapped to the new configuration until I logout of my machine. Here is how to use the command in general:

xmodmap -e "keycode [YOUR KEYCODE] = [KEY] [SHIFT + KEY] [ALT + KEY] [ALT + SHIFT + KEY] [ALT GR + KEY] [ALT GR + SHIFT + KEY]"

Putting it into scripts

Here are my two scripts to switch between my coding keyboard and my normal keyboard.

coding-keyboard:

# Numbers first row
xmodmap -e "keycode 17 = 8 bar"
xmodmap -e "keycode 18 = 9 backslash"
# Special keys
xmodmap -e "keycode 51 = apostrophe numbersign"
xmodmap -e "keycode 91 mod2 = KP_Delete period"
# Umlaut
xmodmap -e "keycode 34 = braceleft braceright"
xmodmap -e "keycode 47 = parenleft parenright"
xmodmap -e "keycode 48 = bracketleft bracketright"

normal-keyboard:

# Numbers first row
xmodmap -e "keycode 17 = 8 parenleft NoSymbol NoSymbol bracketleft"
xmodmap -e "keycode 18 = 9 parenright NoSymbol NoSymbol bracketright"
# Special keys
xmodmap -e "keycode 51 = numbersign apostrophe"
xmodmap -e "keycode 91 mod2 = KP_Delete comma"
# Umlaut
xmodmap -e "keycode 34 = udiaeresis Udiaeresis"
xmodmap -e "keycode 47 = odiaeresis Odiaeresis"
xmodmap -e "keycode 48 = adiaeresis Adiaeresis"

I put those files into my ~/bin folder which is in my path and added two aliases to my .bashrc file:

# add bin folder to path
export PATH="~/bin:$PATH"
alias ck='coding-keyboard'
alias nk='normal-keyboard'

Now I just type nk or ck into my console and I switch keyboards.

A bit UI

I found it quite annoying to use the console to switch keyboards. Especially when I’m in coding mode and start writing a mail in German. I start typing, hit my first Umlaut, realize there is a brace instead, switch to my console which is on another desktop, enter nk, switch back to the mailing-desktop, remove the brace and keep on writing.

So I needed a simple UI. I’m using Pop!_OS as distro which comes with GNOME and I read that it is possible to write extensions with JavaScript (web dev ❤️ starts pumping). But I found no nice tutorial and the documentation seems quite hard to learn. Especially because you can’t use Node.js and must call lots of wrapped system APIs.

But I came across Argos (github, gnome store) which is an awesome project from Philipp Emanuel Weidmann. You write simple bash scripts (or scripts in other languages) which write to std out. Argos uses this output and creates a GNOME Extension from it. For more details check the github page.

I created this litte script that creates a drop down with both keyboard modes. It checks in which mode my keyboard currently is and marks it with a ✔. Here is an image how it looks like:

keyboard switcher GNOME Extension

And here is the code that lives in ~/.config/argos/keyboard-switcher.sh :

Aaand… we are done 😊.

What about quirks?

Every time I talk about this I get the following two comments: What about your muscle memory? and OMG! 😱 I would not do this. You won’t be able to use a computer from another person anymore.

Muscle memory: Well, it takes some time until you start using the new key mapping. It helps by replacing the old key combinations to something else. Then, you notice it quite easily. Actually, I was using my new keyboard mapping just a few hours and started to miss it when I accidentally was in normal mode. So you are getting comfortable pretty soon.

And the other people computer thing? Well, how often do you use a computer from another person? 1–2 times a year? And it’s not like you would not be able to find the keys anymore 😁.

Hope you found this article helpful and it would be great if you leave a comment how you remapped your keyboard and why you used this layout.

--

--