2

I use the following command to remap the Caps Lock key to Esc:

setxkbmap -option caps:escape

Unfortunately, I have to type the command every time I create a new session. I tried putting it in my .bashrc but it did not work. I guess the keyboard settings must be getting overwritten somehow after the .bashrc has run.

How can make the key binding automatically occur?

4
  • 1
    Typically, you would put it in your X initialisation file (~/.xinitrc), but if you are using a display manager, that may not get read. How do you start X?
    – jasonwryan
    May 17, 2016 at 3:16
  • @jasonwryan I don't know it is ubuntu. I just start ubuntu then press Ctrl-Shift-T May 17, 2016 at 3:48
  • 1
    Doesn't Ubuntu have some sort of keyboard utility: you probably need to define it there. This should probably be migrated to AU...
    – jasonwryan
    May 17, 2016 at 3:57
  • 1
    did you try adding the command to startup applications? May 17, 2016 at 4:49

1 Answer 1

2

If your ubuntu is not too old (? probably at least 15.04), you should have a command locatectl which on its own will list some current settings eg:

System Locale: LANG=en_US.UTF-8
    VC Keymap: us
   X11 Layout: us
    X11 Model: pc105

Note the values for layout, model, variant, and options if any and provide them to sudo localectl in that order, with your new option added with a comma to any existing options. If the model is missing it is probably pc105 (see also setxkbmap -print). Eg

sudo localectl set-x11-keymap us pc105 '' caps:escape

You only need to use the command once, as it changes global files and is preserved across reboots. localectl is part of systemd. See man localectl.

2
  • this does not persist through the computer sleeping; when it comes back from sleep the escape key is no longer changed even it says it is changed in localectl May 20, 2016 at 17:55
  • that seems unusual. there really must be something which has another config file it is using to restore a different setting. Edit your question with which version of Ubuntu you are using, in case that helps someone find an answer.
    – meuh
    May 20, 2016 at 18:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .