Bind CAPS+hjkl to arrow keys; CAPS to ESC

I wanted to do the exact same thing, and after some search and experiment, finally got it working.

Solution 1

(See solution 2 below, which is potentially better)

Step 1 (mapping caps_lock + hjkl): Follow this answer and add the config. You should add to the "us" file if you are using the US keyboard layout and skip the other keybindings that you're not interested in. Then run setxkbmap -layout us.

Step 2 (caps_lock as escape): Run xcape -e 'ISO_Level3_Shift=Escape'. You can add this line to your /etc/profile so you don't have to run it manually after reboot.

===================================================

Solution 2 (probably better)

I was happy with solution 1, until I realized I couldn't use the key bindings in IntelliJ, which is a big bummer. Eventually I figured out that I could just use xmodmap and xcape to do the job, while still being able to use them in IntelliJ!

Step 1 (mapping caps_lock + hjkl): Create a file (say "~/.xmodmap") with the following content:

keycode 66 = Mode_switch
keysym h = h H Left
keysym l = l L Right
keysym k = k K Up
keysym j = j J Down
keysym u = u U Prior
keysym i = i I Home
keysym o = o O End
keysym p = p P Next

Feel free to skip the last 4 lines. I pasted them because they might be useful to you as well. In fact I'm really hoping to get the caps_lock enhancement working in Linux.

Then, run xmodmap ~/.xmodmap.

Step 2 (caps_lock as escape): Run xcape -e 'Mode_switch=Escape'.

Step 3 (optional): To avoid manually applying the keybindings, put the above 2 commands into your /etc/profile.