Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a bash script that I use to configure a vanilla Ubuntu (10.10 Maverick Meerkat) installation to be exactly the way I want it. I make extensive use of gconftool-2 to configure the desktop, set up shortcut keys, etc.

Now, I'm trying to swap the CTRL and CAPS keys. I have found two ways of doing this:

  • In Gnome, go to System -> Preferences -> Keyboard -> Layout -> Options and make the change in there. This works well, but I don't know how to script this; the setting doesn't seem to be stored in the usual place as I can't find it with gconf-editor.

  • Add the line setxkbmap -option "ctrl:swapcaps" to my .bashrc file. That works too, until I suspend the machine & then resume it. At that point the CTRL and CAPS behaviour return to normal, until I cause .bashrc to be run again by opening a new shell. This behaviour has been reported as a bug in RedHat.

Could someone please suggest a way of switching those keys that is both permanent, and can be scripted? I'm sure I must be missing something obvious here ...

share|improve this question
add comment

2 Answers

I have accomplished this on my RHEL system in a generic way by adding this to the beginning of `~/.xinitrc:

xmodmap ~/.xmodmaprc

And the contents of .xmodmaprc:

!! Swap Caps_Lock and Control_L
remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L
share|improve this answer
add comment
up vote 0 down vote accepted

There's an even quicker Gnome-only solution. Thanks to this post from gmargo over on Ubuntu Forums:

If you're running Gnome, then all you need to do is create a file $HOME/.Xkbmap with this content:

-option ctrl:swapcaps

Log out then back in.

Update: I just confirmed that the setting lasts across a suspend/resume.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.