I am a massive proponent of streamlining my workflow and I feel one of the biggest improvements I've made in this area is simply navigating my computer. It's something I don't hear about much, in fact I know a few devs that don't even learn the hotkeys that come with Windows or their IDE and are happy to point and click their way through the day. Although there is nothing wrong with this I personally feel that there are massive benefits in shortcuts, hotkeys and macros.
I've fallen in and out of favour with Vim over the last couple of years, having only been developing for 3-4 years Vim keeps sucking back into its black hole. I manage to stay out of it most of the time nowadays but what's really appealing about Vim for me is the mouseless operation, I really took to the idea of not having to move your hands away from the home row.
Apart from looking like a 90's hacker
there are productivity gains in not using the mouse or even the arrow keys.
I set out originally only looking for a solution to move my arrow keys to the home row permanently. To do this there were a few problems that had to be solved:
How to implement it (What program?)
How would the keys be activated? (What modifier?)
I had used AutoHotKey in the past but had drastically underestimated the power of this tool by only using it to create the odd macro for repeating tasks at work or for games. After researching other options (AutoIt and Kantu) I decided to go with AutoHotKey as it seemed well documented, mature and I had previous experince.
It's worth noting I did find a handy browser extension that does fulfil some of my requirements (re mapping of arrow keys) but only in chrome. Vimium adds basic vim-like navigation to the browser but unfortunately I couldn't leverage it as it only works in the browser. Definitely worth a look as it's a plugin I still use daily.
I had started to address what key would be used to modify the home row to allow for the input of arrow keys in a vim-like style:
After debating for what seemed like an age if to use CTRL, ALT or WIN/META keys I came across an article which was talking about swapping the escape and CAPSLOCK and there it was... staring me right in the face gathering dust...
I started practising hotkeys with the caps under my little digit and it was a pure penny drop moment. It felt so comfortable and natural compared to anything that lives on the bottom row.
Let's be honest, it's probably the most wasteful key on the keyboard:
- It's massive
- The functionality it brings can be achieved by holding shift
- It's used much less than other more useful keys that are harder to reach like ESCAPE and most of the keys on the bottom row
This was probably the trickiest part of setting this up. I wanted this new modifier to work well, as a modifier. The issue with this is that there are only a few keys that work as modifiers namely:
- ALT GR (CTRL + ALT (most of the time))
We could just swap CTRL and CAPS which isn't a bad deal, you don't have to learn any new combinations/macros and get all the accessibility benefits of using CAPS. The issue with this approach is that I want to make my own macros and it's much easier to start with a blank slate then it is to figure out which commands you might be overwriting in different programs by remapping CTRL + whatever to your own macro.
I attempted to create this functionality in AutoHotKey and after hours of messing around and then the subsequent google session I found the following snippet to do what I wanted:
#Persistent SetCapsLockState, AlwaysOff ; Caps Lock Disable capslock::return ; Caps Lock with shift+caps +Capslock:: If GetKeyState("CapsLock", "T") = 1 SetCapsLockState, AlwaysOff Else SetCapsLockState, AlwaysOn Return
The snippet achieves two things:
- It turns CAPSLOCK off so it doesn't work as CAPSLOCK
- Enables SHIFT + CAPSLOCK to recreate normal CAPSLOCK functionality
Not only can I now assign whatever I want to CAPSLOCK + my_desired_key but I can turn caps lock back on if needed with SHIFT + CAPS.
I don't know how to measure how much time I had put into finding a way to "Add" a modifier up until this point, all I can tell you is when I found this my head didn't leave my desk for 10 minutes 🤦♂ As always the simplest solutions prevail!
For example to assign CTRL + c to CAPSLOCK + c it would look like this:
Capslock & c::send, ^c
If you're not familiar with AutoHotKey the part on left-hand side of the '::' is the combo you would like to press. On the right-hand side is the command to execute, so 'send, ^c' means Send keys CTRL + C.
In this context ^ = CTRL see here for a full reference
So now we can define custom hotkey combos to do tasks for us this is what it looks like to remap the directional buttons to the home row:
CapsLock & h::Left CapsLock & j::Down CapsLock & k::Up CapsLock & l::Right
Easy, right? So let's take it a bit further. Above the arrow keys, I like to have some of the keys you would typically find in between the main set of keys and the Numpad.
Adding those in is as easy as
Capslock & y::Home CapsLock & o::End CapsLock & u::PgDn CapsLock & i::PgUp
This, in combination with the arrows not only is more comfy but has levelled up my navigation skills in a big way 💪
While we are on the topic of navigation here are the other useful commands I use for navigating my computer:
Capslock & space::Escape CapsLock & <::BackSpace CapsLock & >::Delete CapsLock & 1::switchDesktopByNumber(1) CapsLock & 2::switchDesktopByNumber(2) CapsLock & 3::switchDesktopByNumber(3) CapsLock & 4::switchDesktopByNumber(4) CapsLock & 5::switchDesktopByNumber(5) CapsLock & s::switchDesktopByNumber(CurrentDesktop + 1) CapsLock & a::switchDesktopByNumber(CurrentDesktop - 1)
See here for the desktop switching function
Now you have the basics of creating your own layer of hotkeys what will you do with it?
If you're interested in learning how to do this on Linux let me know with a comment below and I will show you how I translated this to my Linux rig.
📕 TLDR: Remap useful keys to a custom layer/new modifier using AutoHotKey