Recently I started learning to touch type, and noticed one annoying problem.

You hold your fingers on ASDF and JLK;. While you learn (and I believe, it will matter even once you achieve some level of mastery), you make mistakes and have to erase a lot. See the problem? Backspace is damn far away!

Fine then, let’s find an alternative

Okay, now, which key would be a better candidate? Something that is within reach and something I rarely use. Caps Lock is the perfect bet, it is right by myleft pinkie. If I can move it to somewhere else, say, Scroll Lock and make it a Backspace instead, that would make typing way more comfortable.

Remapping keys

Since I’m on Linux, I use the xmodmap utility, available on Ubuntu right away. First of all, let’s get the information about desired keys: Caps Lock, Backspace and Scroll lock.

xmodmap -pk | grep -i -E "caps|backspace|scroll_lock"

Here’s what the result looks like

 22    	0xff08 (BackSpace)	0xff08 (BackSpace)	0xff08 (BackSpace)	0xff08 (BackSpace)	
 66    	0xffe5 (Caps_Lock)	0x0000 (NoSymbol)	0xffe5 (Caps_Lock)	
 78    	0xff14 (Scroll_Lock)	0x0000 (NoSymbol)	0xff14 (Scroll_Lock)	)	

So we simply need to remap Caps Lock to key 78, and then remap BackSpace to key 66

Let’s do it!

xmodmap -e "keycode 78 = Caps_Lock"
xmodmap -e "keycode 66 = BackSpace"

# This command was needed in my case. Without it, Caps Lock will perform Backspace's function, but it will also keep triggering the... well, Caps Lock.
xmodmap -e "clear Lock"

I found this last hack here.

That’s it! Now when you press Caps Lock, a symbol is erased, and when you press Scroll Lock, all caps mode is toggled.

Why didn’t you just swap Caps Lock and Backspace?

Because this trick doesn’t work in every program for me. For example, in Visual Studio Code, it doesn’t read Caps Lock as Backspace and doesn’t erase symbols. So I had to preserve the original Backspace.

In conclusion

There are some inconsistencies to this appoach. It might not work on all computers and keyboards. And it works only in your graphical interface, so no magic in TTY this way. There might be a different solution, I haven’t explored it yet.

Linux is very customizable. Remapping keys is often done out of the box. I’m not sure if there is a way to do it reliably, but that’s something already!

Thanks for dropping by! I’ll see you eventually.