Recently I have been trying to use a bit more Emacs. A thing that I have just postponed was changing the CapsLock key to the Ctrl key.
It is really simple to do this on the X server. You have to install xev to see to what is the number binded to the CapsLock key. After running xev in the terminal a new screen will show, and in here touch the CapsLock Key, a message like the following will appear
KeyPress event, serial 34, synthetic NO, window 0x1e00001,
root 0x936, subw 0x0, time 702421, (658,1002), root:(666,1028),
state 0x02, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES,
XLookupString gives 0 bytes:
XFilterEvent returns: False
The only thing we care for at the moment is the keycode which in my case is 66.
Create a new file called ~/.Xmodmap and enter the following configuration.
remove Lock = Caps_Lock
keycode 66 = Control_L
add Control = Control_L
Run the command xmodmap ~/.Xmodmap and that's it. In my case I run i3 so I added this command at the end of my config like the following.
exec --no-startup-id xmodmap ~/.Xmodmap
So I just found out that there is a cli command that just changes the key:
setxkbmap -option ctrl:nocaps
. It is simpler and cleaner.