Use xev to find out which key you want to remap. Then create ~/.Xmodmap.
Here’s an example of to remap a key:
Add the following line to your .bashrc or .zshrc to make it permanent:
Remap <Caps_Lock> to <Escape>
When using GNOME
If you’re using GNOME, you can remap the <Caps_Lock> key by following these steps:
- install
gnome-tweaks; - go to Keyboard and Mouse;
- go to Additional Layout Options;
- click on Caps Lock behavior;
- click on Make Caps Lock an additional Esc.
When using i3
If you’re using i3, add this to the end of your i3 configuration file ~/.config/i3/config:
To take effect, you have to restart i3. You can do this by logging out and logging back.