You should remap you keyboard using Vim key bindings
This will change the way you use your computer ever
6 min read
Table of contents
- I love my keyboard after switching to Vim-like key bindings
- Keyboard is more important than the mouse for programmers
- Bring your most frequently used keys very close to you hand rest position
- Reuse the close-up but useless key as much as possible
- Enjoy using your keyboard!
I love my keyboard after switching to Vim-like key bindings
I can start an article talking about why I highly recommend using Vim editor to replace your traditional text editor especially when your are programming. Yet this is yet another topic to be discussed. Most important take away from the Vim editor is the way that it designs its key bindings. The most inspiring one is the use of
hjkl for arrow movement. It saves a lot of arm movements between your hand rest position and arrow keys when you want to to move your cursor. When you're editing text, especially when editing source code, you probably need to move the cursor very frequently. There's no point to put the arrow keys so far away from reach of your right hand. Just this key bindings has inspired me to redesign my keyboard layout entirely.
Keyboard is more important than the mouse for programmers
The mouse is more intuitive to use for sure, it is a very good way to discover the user interface. However, for some routine task that you have done hundreds times already, efficiency becomes more important. You no longer need to discover the action, but you just want to finish the task by as little effort as possible. in this case, your keyboard is more important than your mouse, because using keyboard shortcuts in general will be much faster than finding the mouse pointer and click something. If you have already trained up your muscle memory for Vim, your overall experience on using your computer will be much improved. Normally, your hand position would be resting on
jkl; keys respectively. By using the correct key bindings, you don't need to spend effort finding the right position for both of your hands on your keyboard.
Bring your most frequently used keys very close to you hand rest position
If you have ever learn how to use a keyboard, you know there is a natural rest position for both of your hands. I will not go through a how to use your keyboard lessons, but in general, your left hand and right hand should be resting on
jkl; respectively. After typing, all of your fingers should return to the rest position for optimised speed. Base on this principle, you should think about your workflow, and the general idea is to bring the most frequently used keys as close to your hand rest position as possible. I'm going to share some of my favourite custom key bindings and explain them briefly. But there is no right or wrong answer for key bindings, it all depends on personal preferences. I just share my best match for myself after many hours of trial and discovery.
Right Alt + hjkl for arrows
Arrow keys it's very important for editing text. There is absolutely no reason to put those arrow keys very far away from your rest position. You may switch to a smaller form factor keyboard, this already helps a lot. However, you still need to move away from your resting position in order to reach those arrows keys. Why not just bring the Vim key bindings to your whole system? My solution is to use a so-called
Level 3 Shift key to trigger my hjkl key to become arrows. For most Linux system, you can do this pretty easily by using
xmodmap command. However, this command only works in X11 display system, while most Linux distro nowadays has switched to use Wayland. The solution is to remap your key before any display system. While I can't find any ready to use solution on the web, I ended up writing a program in Python to implement it my self. How to program a keymapper in Python is yet another topic to discuss.
Right Alt + nm,. for Home, PgDown, PgUp, End
When I edit text, I often need to go to the beginning or end of the line just to press enter to get a line break, or press Backspace just to join with the previous line. If it is a really long line of text, I often have to use the arrow key just to go to the beginning or end of the line, which ended up wasting a lot of time and effort. If you can somehow remap you Home and End key to a key combo very close to your rest position, it can drastically increase your editing efficiency.
Right Alt + ui for Backspace, Forward Delete
The Backspace is very often used when you have a typo. But what happened if you want to delete the character after your cursor? You need the Delete key, which is, surprisingly, very far away for a normal keyboard layout. You often need to use arrow key to place your cursor after your typo, and then hit Backspace key to remove the typo. Why don't we learn from macOS? They have a Forward Delete key bindings using Cmd + Backspace! You can also do this on Linux by remapping Shift + Backspace to Delete key, which I have already done. But my even better solution on Linux is to use Right Alt as Layer 3 Shift, and map Right Alt + y/u as Backspace, and Right Alt + i/o as Delete. When using Layer 3 Shift, you basically have a reflex action that the layer 3 has nothing to do with the meaning of character, only something related to editing direction. So it is not very hard to remember Right Alt +
i/o are actually representing the direction of word deletion.
Reuse the close-up but useless key as much as possible
Since computer has been evolving for so many years, keyboard layout more or less stayed unchanged for many years. One of the most useless key I've came across is the
Caps Lock. If this key is broken, you will find you can still use your computer pretty normally, isn't it? It very much makes sense to remap this key to do something useful.
Remap Caps Lock to Escape
My preference is to remap the Escape key to Caps Lock. Escape key is very often used, but it's very far away. If you are a Vim user, the Escape key is of utmost important, it's responsible for switching between insert mode and normal mode. After doing this key remap I found my Vim editing motion has never been so smooth!
Swap Left Ctrl and Left Alt
If you are a macOS user, you will probably agree with me on this. Because when you copy and paste text, the key bindings for macOS (Cmd + C/V/X) will be much smoother than Windows or Linux (Ctrl + C/v/X). It's because the Cmd key for macOS is the one next to the Space, so you can easily press it with your left thumb. But for the Ctrl key in Linux, you need to use your weakest little finger, and also need to move away from the natural rest position. So when I setup a new Linux machine, I will always swap Left Ctrl and Left Alt key system wide. For modern keyboards, they usually have a
Win key, which can actually be used as the Left Alt key, so you may also consider swapping the Left Ctrl, Left Alt, and Left Win key altogether.
Enjoy using your keyboard!
As a programmer, your keyboard is probably the most touched thing everyday. So it is definitely worth spending some time to make it better. Now, not just the keybindings for IDE, but I also change my keybindings for web browser, or even apply some of them system-wide. Simple say, by changing a few keybindings, you will end up change the whole way you use your computer.