I want to remap caps lock to escape in X11 (i.e. pressing the physical caps lock button will be interpreted as esc by applications and esc's behavior will not change). The solution must survive an X restart. xmodmap and setxkbmap are acceptable solutions (as are similar programs). I don't want to deal with a GUI, as I want the solution to be portable and a part of my dotfiles. If I'm missing a better/easier/more obvious solution, please tell me, though do note that I am not using a DE (trying out i3wm).
So far I've tried using xmodmap and setxkbmap with little success.
Here's my attempt at using xmodmap:
# ~/.xinitrc xmodmap ~/.xmodmap
# ~/.xmodmap remove Lock = Caps_Lock keysym Caps_Lock = Escape
$ xmodmap ~/.xmodmap from the command line works and does what I want. The issue is that this gets reset every time x restarts. That's where I expect the xinitrc to come in--shouldn't it load every time x starts and run the xmodmap command? If the command works, why doesn't it do anything when read from a file?
I've tried a couple of things with setxkbmap, neither of which worked. The two attempts below were in the file at separate times.
# ~/.xinitrc setxkbmap -option caps:esc # attempt 1 setxkbmap -option esc:nocaps # attempt 2
Neither command did anything perceptible from the command line, so I'm assuming that I've got the command wrong. I like the idea of this solution because it's a one-liner and does not require anything in some other file. If only it worked.
Is .xinitrc the wrong file to be using? I know startx is loading from ~/.xinitrc.
I request that possible solutions contain the whole file(s), not just one line (if more than one is required in the file) so I don't mess up some intermediary step. For example, if I need something in .xinitrc and something in .xcapsrebind, please show both files and all of the required contents (I can also handle being told to append something to the end, but if an & or similar may be required, please tell me).