Keyboard layout using XKB for coding

Keyboard layouts are something that should be ergonomic, but most of them aren’t. And as we’re all big creatures of habit, we don’t switch to better ones. Me included. Nevertheless, even if I’m using python a lot and brackets there are not as widespread as in other languages, I still got annoyed about them enough coding it with my German keyboard layout, to look for some improvements. English layout only partly improves the situation, as there is a bunch of brackets still not comfortably reachable. I was also always quite jealous on vim and emacs users, that they could tell their editors to use some keyboard shortcuts for cursor movement, but eclipse is too retarded for this. Nevertheless, keyboard shortcuts in vim also suck quite a lot, as they are adjusted for keyboards from stoneage. E.g. vim uses HJKL for left, up, down and right, so it’s shifted exactly by one key to the left compared to the standard position. Using ESC instead of TAB also seems to origin from that times. Changeing this consequently for all derived commands seems to be a quite a messy adventure deep into vims config. So it also sucks.

Fortunately using Linux the solution is easy. Some XKB configuration does the job:

xkb_symbols "coding" {
    include "de(basic)"
    name[Group1]= "German (with extra brackets and cursor)";

    key 	{ [         i,          I, Up ] };
    key 	{ [         o,          O, bracketleft ] };
    key 	{ [         p,          P, bracketright ] };

    key 	{ [         h,          H, BackSpace ] };
    key 	{ [         j,          J, Left ] };
    key 	{ [         k,          K, Down ] };
    key 	{ [         l,          L, Right ] };
    key 	{ [odiaeresis, Odiaeresis, parenleft ] };
    key 	{ [adiaeresis, Adiaeresis, parenright ] };

    key 	{ [    period,      colon, braceleft 	] };
    key 	{ [     minus, underscore, braceright, emdash] };

    include "level3(lwin_switch)"
    include "level3(caps_switch)"

The pasted 20 loc in the file /usr/share/X11/xkb/symbols/de plus according lines in xkb/rules/evdev and xkb/rules/evdev.xml fix the issue. What it does is to throw away the totally useless CapsLock functionality and rebind it with the function of AltGr. This way you can easily switch to level 3 key functions with your left hand, and we can throw in a bunch of new functionality to the right hand side. There we have cursor functionality for the keys IJKL, [ ] on OP, ( ) on ÖÄ and { } on , and -. We also have a new backspace on H.

I’ll probably also add some more stuff for the left hand side, as AltGr is quite nicely reachable with the right thumb, and I’d actually like to reduce the load on the left pinky some more. Doing lots of text marking, copying, inserting, holding down shift and pressing control a lot, it’s much more stressed when editing code, then when writing plain text. So the weakest of all fingers has to do most, which is quite weird and definitely awaits another fix.

Leave a Reply