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.
Third, 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 and to the Input tab. Uncheck the following settings:
- Follow system keyboard layout
- Enable key equivalents under X11
- In X11 go to Applications/Terminal to open up a Terminal window
- Type the following in the Terminal window:
vi ~/.Xmodmapand 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 the following text:
! ~/.Xmodmap
clear Mod2
clear control
keycode 63 = Control_L
keycode 67 = Control_L
add control = Control_L - Now press ‘esc’ or the Escape key to exit the Insert Mode and return to the Command Mode. Now type
:wqand press Enter. This command tells Vi to Write (think ‘Save’) the changes you made to the file and Quit Vi itself. - Type
xmodmap ~/.Xmodmapand press Enter to complete this process. - 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 post uses information found at //extrabright blog and The University of Illinois at Chicago’s Unix 101 pages on Vi. This is my attempt to write a more concise how-to.



June 1st, 2008 at 10:34 pm
Great tutorial!
Do you know how to do this the other way too?
As in, make the Control key act like the command key normally would?
June 2nd, 2008 at 12:03 am
@yopogs:
Thanks for the comment!
As for your request, I’m pretty sure that ‘63′ is the control key and ‘67′ is the command key according to X11. So, follow the above instructions, but for 63 put Meta_L instead of Control_L. Let me know if that works.
The tough part is that the whole Control+Click as right-click… well, it’s as though you are trying to split the characteristics of one button into two. I recommend you purchase a multi-button mouse if you’re still using a one-button Apple mouse. Logitech makes some fairly inexpensive Mice that work well with OSX ($20 - $30). I used an older Logitech MX310 on my G5 and it worked great. You’ll never go back.