Coder's Cat

Swap Caps Lock and Control

2020-12-09

After almost 15 years of programming life, I always want to swap the Control and Caps Lock with my keyboard. I began to do so because I need to use Emacs , and Control is the most used key in many key bindings in Emacs. I started to experienced Repeated Strain Injury after several years of working, swap these two keys saved me.

Not only in Emacs, we actually use Control much much more than Caps Lock, but Caps Lock is usually put in a better position in most keyboard layouts. This standard keyboard layout began almost at 1984, when IBM PC keyboard introduced Model F (PC/AT).

84-key PC/AT keyboard

HHKB is an alternative if you want a keyboard with a default layout that prefers to programmers. If you are a Vim/Emacs user, buy one for yourself!

It’s also easy if you want to swap these two keys.

Windows

The easiest way is installing PowerToys, and config it in Keyboard Manager:

image-20201209144814896

Remember to keep PowerToys run in administrator mode.

image-20201209145005272

There are some other ways such as using regedit to modify, but I haven’t tried it.

Mac

Go to Apple Menu -> System Preferences… -> Keyboard -> Keyboard Tab -> Modifier Keys and select Control for Caps Lock.

Linux

x11

When running XWindows you need to modify the X11 key map using xmodmap. It is not sufficient to just modify the console keyboard mapping. Use xmodmap to load the following keymap file (save in ~/.Xmodmap):

remove Lock = Caps_Lock
keycode 0x42 = Control_L
add Control = Control_L

make these changes persistent

These keyboard settings are not persistent after a reboot. Most Linuxes will load your ~/.Xmodmap file when you log in with xdm or gdm. Some don’t. If not then you should add this line to your ~/.xsession and ~/.xinitrc files (after the shebang #!/bin/sh line):

[ -f ~/.Xmodmap ] && xmodmap ~/.Xmodmap

Gnome

If you are using GNOME, try to install Gnome Tweak Tool:

sudo apt-get install gnome-tweak-tool

For version 3.30.0 and later:

  • Open the tweak-tool and click on the Keyboard & Mouse section in the left menu bar.
  • Click on the Additional Layout Options button on the left.
  • Under Caps Lock behavior select Caps Lock is also a Ctrl.

For older versions:

  • Open the tweak-tool and click on the typing section in the left column.
  • You should now see the line Caps Lock key behavior on the left.
  • Choose Make CapsLock an additional Ctrl key instead of Disabled in the drop-down list and you should be good.

Enjoy your new Control!

Join my Email List for more helpful insights, It's Free!😋

Tags: Misc