X11: Switch Control Key To Apple/Command Key

One of the major problems with using X11 to run *NIX applications on OSX is switching from using the Apple/Command/⌘ key to using the Control key as your primary modifier key.

First of all, I don’t understand why the Control key is where it is on keyboards for OS’s that use it as the primary modifier key. It is probably the least ergonomic key to use (unless you have the good fortune of using a Thinkpad, since they don’t include the Windows key). Apple, for all its missteps, gets it right by making the primary modifier key easy to press in combination with other keys. Command, Control, Apple, ⌘, whatever you call it, put it in a comfortable spot! That one detail almost prevented me from switching to something other than OSX. Seriously.

With that said, it’s no surprise that Apple puts the rarely-used-in-OSX Control key off to the far corners of the keyboard. As to why Apple doesn’t include an option to switch the Control/Command keys in the X11 preferences, I can only imagine.

Second, making this change isn’t for *NIX purists that like it the way it is. Don’t get pissed at me. I’m just trying to help Mac people enjoy the fruits of the Open Source community because I’m frustrated with Microsoft and Adobe (and even Apple). Their customers take a back seat to their interest in making money.

Let’s Get Started!

This is simple and if anything goes wrong, it’s easy to get back to where you started. Here’s the meat and potatoes:

Start the X11 application

In X11 go to X11 > Preferences > Input tab. Make sure that the following options are UNCHECKED:

Follow system keyboard layout

Enable key equivalents under X11

Close X11 Preferences.

Open the Terminal.app (Applications > Utilities > Terminal.app)

Type the following in the Terminal window:vi ~/.Xmodmap and press Enter. This will open a file named ‘.Xmodmap’ located in your home folder ‘~/’ with the text editor program called Vi. Don’t be frightened!

Vi is run from within the Terminal, so it won’t look much different. Press ‘a’ to switch to Vi’s Insert Mode (I think the ‘a’ stands for ‘Append’) and then type in or copy/paste the following text:! ~/.Xmodmap
clear Mod2
clear control
keycode 63 = Control_L
keycode 67 = Control_L
add control = Control_L

If you have a MacBook and want to use both the left and right ⌘ keys, use this version instead:! ~/.Xmodmap
clear Mod2
clear control
keycode 63 = Control_L
keycode 67 = Control_L
keycode 71 = Control_L
add control = Control_L

Now press ‘esc’ or the Escape key to exit the Insert Mode and return to the Command Mode.

Type :wq and press Enter. This command tells Vi to Write (think ‘Save’) the changes you made to the file and Quit Vi itself.

Type xmodmap ~/.Xmodmap and press Enter to complete this process.

Quit Terminal.app

Open something in Gimpshop, Gimp, OpenOffice, Inkscape or any X11 application that you use to test if you have successfully switched to the Apple/Command key.

If you suddenly cannot get any of your X11 applications to start, you can delete the .Xmodmap text file from your home directory. To do this, open a Terminal in either the X11/terminal or the OSX Terminal.app: rm ~/.Xmodmap and press Enter. The command rm stands for ‘Remove’. Be careful with this command. There is no ‘undo’ in the command line.

This entry was posted
on Wednesday, January 2nd, 2008 at 11:55 am and is filed under Linux, OSX.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.