Radu Cotescu's professional blog

g33k w17h pa45510n

Remapping Keys in Ubuntu 14.04

Ever since I’ve switched to Mac OS X I liked its shortcut modifiers more than the ones available on Windows / Linux. While I do agree that sometimes you lose count of the number of modifier keys that you have to press in order to get something done, most of the cases that claim is just FUD.

The ergonomy of the Mac has also made its way into how shortcuts are defined. The Command key, positioned where Alt is on PC keyboards, is definitely better positioned when it comes to using that key as your main modifier for shortcuts. Call it the power of habit, but every time I switch to a PC I find myself pressing the Alt key instead of Control. And that’s because Alt is in a handier position.

A few weeks ago I bought a CODE ten-keyless mechanical keyboard. One of the nifty features (and there are plenty) is the ability to change the layout of your keyboard with a combination of DIP switches located on the back. Obviously, it can be configured to a Mac layout. But what do you do when you want to use the same keyboard on your Linux box, from time to time? I mean you’re mostly using Command for your shortcuts. Remapping the shortcuts in your head to Control is not that easy at first.

"CODE 87-Key Mechanical Keyboard with Mac layout"


Luckily Ubuntu, like many other Linux distros, comes with xkb - the X KeyBoard extension. This extension is responsible for mapping the physical keys of your keyboard to their designed function. xkb symbol files can be found in /usr/share/X11/xkb/symbols and it’s good to know that they’re localised, in case you need to add some language-specific mappings. However, in my case, I need to remap some of the modifier keys.

The modifier keys are mapped in /usr/share/X11/xkb/symbols/pc, a file which is inherited by all other configurations. Since I just want to replace Super with Control, the changes are minimal:

key <LCTL> {    [ Super_L       ]   };
key <LWIN> {    [ Control_L     ]   };
key <RCTL> {    [ Super_R       ]   };
key <RWIN> {    [ Control_R     ]   };

In order to apply the new mappings you need to clear out xkb’s cache from /var/lib/xkb:

rm -rf /var/lib/xkb/*

Afterwards just restart your X session and you’re good to go. Even though this small change doesn’t make all shortcuts to work like on a Mac it’s still a lot better than without it.

Linux, Ubuntu

« Coloured log outputs on Unix/Linux