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 am trying to set up my computer so that the escape key performs the caps lock function and caps lock performs the escape key function. I have a small script to swap my escape and caps lock using xmodmap. In my .bash_profile, which is in my home directory, I put this line:

xmodmap ~/.capsswap

which to my knowledge, should run .capsswap, which I have in my home directory as well, when I log in.

the contents of .capsswap are

  1 ! Swap caps and Escape
  2 
  3 remove Lock = Caps_Lock
  4 keysym Escape = Caps_Lock
  5 keysym Caps_Lock = Escape
  6 add Lock = Caps_Lock

I am running Ubuntu 12.04.1 LTS.

Basically this isn't working as nothing happens on when I log in. I'm pretty new to using bash and xmodmap in general, and I could be totally wrong with what I am doing, so if anyone knows how to fix this problem, or can suggest a better way to swap the escape and caps lock, please let me know.

share|improve this question

migrated from stackoverflow.com May 7 '13 at 7:55

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

up vote 1 down vote accepted

Move ~/.capsswap to ~/.Xmodmap

~/.Xmodmap is read by /etc/gdm/Xsession.

If you're not using gdm, you could add a script named: 91xmodmap

in /etc/X11/Xsession.d/

that contains:

XMODMAP="$(which xmodmap)"
SYSMODMAP="/etc/X11/Xmodmap"
USRMODMAP="$HOME/.Xmodmap"
if [ -x $XMODMAP ]; then
    if [ -f "$SYSMODMAP" ]; then
        $XMODMAP "$SYSMODMAP"
    fi
    if [ -f "$USRMODMAP" ]; then
        $XMODMAP "$USRMODMAP"
    fi
fi

The command you put in your ~/.bash_profile isn't running because gnome-terminal doesn't run as a login shell by default.

Right click on gnome-terminal's screen and go to Profiles -> Profile Preferences.

Then under the Title and Command, check Run command as a login shell.

share|improve this answer
add comment

Ubuntu has a GUI for changing the CapsLock behavior

Open Keyboard Layout settings and click Options. You can select the Caps Lock key behavior in there.

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.