Remapping Your Macbook's Keyboard in Ubuntu 12.04

I just installed Ubuntu 12.04 (Pangolin) on the Macbook Pro that I got from work. The fact that Apple rearranges the has a different bottom row of keys drives me nuts, though. The placement of the Command keys are where the Alt keys should be, and there is no right ctrl key. My muscle memory is trained for a standard keyboard and fighting it, especially while coding, slows me down a lot.

Luckily, there's a utility called xmodmap that will let you remap these keys however you want. Here's what we're going to do_

Drop the following code into a text editor and save it somewhere. I saved it as .xmodmappings in my home directory_

! clean most of the modifiers
clear control
clear mod4
clear mod1

! -----------------
! left side
! ----------------
! keycode 64 is the left alt key
keycode 64 = Super_L
! key code 133 is the left command key
keycode 133 = Alt_L Meta_L

! ------------------
! right side
! -------------------
! key code 134 is the right command key
keycode 134 = Alt_R Meta_R
! keycode 108 is the right alt key
keycode 108 = Control_R

add mod4 = Super_L
add mod1 = Alt_L Meta_L
add mod1 = Alt_R Meta_R
add control = Control_L
add control = Control_R

To test this, drop into a terminal and type

$ xmodmap ~/.xmodmappings</code>

It should make the following changes_ Left Alt -> Left Super Left Command -> Left Alt Right Command -> Right Alt Right Alt -> Right Ctrl

Now test it out. If everything looks kosher, you can set this to run every time by pulling down the gear/power menu from the taskbar, choosing "Startup Applications", and adding a new item containing the above command.

Note that this works on a 7th-gen Macbook, and the layouts may differ slightly on other models. If it doesn't work for you, running xev from a terminal will let you discover the keycodes for your model, which you can substitute into the above script.


Written by Ward -

Saying that Apple "rearranges" the keys is a bit misleading. Apple's keyboard design dates back to a time before IBM PC dominance and the establishment of that as *the* standard keyboard layout. They arranged the keys; they did not "rearrange" them. By the time the PC keyboard became a standard, Apple had a bug customer base it didn't want to piss off by rearranging it layout to match the Wintel platform. Plus,mthose modifier keys are used differently on Mac where an Windows/Linux, so it would harm usability. Apple does make it relatively easy to remap the keys if you're running Windows on a Mac, or using a PC keyboard under Mac OS X. On Linux you're on your own, but isn't that how you guys like it? ♥, your friendly Apple partisan

Written by Chris -

Duly noted. Thanks for the history lesson. More than anything, I suppose I'm annoyed that my job just hands out macbooks instead of letting me choose a Thinkpad or something (First world problem!). It's not like they don't know linux - all our servers and workstations are Ubuntu. Supporting a single platform/disk image makes life easier for them, I guess, but I'd be happier with something else.

comments powered by Disqus