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.

doraemon
  • 421
  • 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 https://unix.stackexchange.com/a/66657/222377 for examples on setting and https://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 07 '17 at 04:47

3 Answers3

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.

Javier
  • 274
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:

samsam
  • 1