2

I googled this topic and a lot of people suggesting

setxkbmap -option ctrl:nocaps

I put this line into my .bashrc. However, frequently this key binding is disabled automatically. This happens randomly when I am doing other things. It is the most annoying when I am using vim, a lot of key mappings are affected. I need to open a terminal to re-run the previous command, which will get it work for another random period of time until it is deactivated again.

Does any one shared the same experience? How to have this mapping permanently?


I finally figured out that it is ibus that resets the key map every time I change input engine.

1
  • 1
    in default ubuntu, desktop environments (GNOME/Unity/KDE etc) provide a settings daemon to maintain the user's preferences. using setxkbmap is a lower level tool that does not communicate with the DEs, and the resets you see are the daemons changing back to whatever preferences they know about. see unix.stackexchange.com/a/66657/222377 for examples on setting and askubuntu.com/a/582498/669043 for an example on disabling the GNOME daemon. note the gsettings commands in those answers may be outdated for modern GNOME.
    – quixotic
    Nov 7, 2017 at 4:47

3 Answers 3

1

Just to clarify: this only works with X11, right?

It's not map the key every time you start a terminal. It's not part of the configuration of the terminal itself but of X.

Create the file ~/.Xmodmap and add the following:

remove Lock = Caps_Lock
keysym Caps_Lock = BackSpace

This will map CapsLock to Backspace.

Of course, you can bind it to Control, if you want.

From the comments: beware that ibus can reset this configuration when changing input.

9
  • I am using X11. I don't know whether setxkbmap is to set for X11 or not. How about the way you suggested? Is it a setting for X11 or for the terminal?
    – doraemon
    Nov 7, 2017 at 3:27
  • By the way, when will it start to be effective? After each reboot or re-login or starting new terminal?
    – doraemon
    Nov 7, 2017 at 3:28
  • xkb is for X so this will work only there. You must restart you session (logout).
    – Javier
    Nov 7, 2017 at 3:32
  • Thank you @Javier, how about the .Xmodmap approach? Also logout?
    – doraemon
    Nov 7, 2017 at 3:33
  • 2
    thanks @Javier. I finally figured out that it is ibus that resets the key map every time I change input engine.
    – doraemon
    Nov 8, 2017 at 1:26
0

For you reference, I was trying to fix this and I propose my solution in another thread Map Caps Lock to Control in Linux Mint

0

Yes, I've also experienced the same problem that "setxkbmap -option ctrl:nocaps" suddenly stops working.

The following remaps the keys permanently and works fine on my laptop:

sudo setkeycodes 3a 29

In case scancode (3a) or keycode (29) is different, you can find out the right one using:

sudo evtest

But for some reason this doesn't work with a USB keyboard. The following works with USB keyboard: https://github.com/stefansaraev/keytable

git clone https://github.com/stefansaraev/keytable.git
cd keytable/
make
sudo ./keytable -k 0x70039=29 --device /dev/input/event5

Get the correct device, scancode (70039) or keycode (29) the same way as before. Some references:

You must log in to answer this question.

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