Best Vim/Evil escape sequence BONUS: Hardware Vim

I’ve been using Vim’s modal editing for … oh dear… over 20 years. How time flies!

Unsurprisingly, the power of this paradigm is the ease with which one swaps modes; particularly, how one exits input mode where all primary keys send their printed output.

What’s in the box?

Out of the box, Vim offers a few ways to accomplish this; Escape, Control+c, Control+] (which is actually synonymous with Escape). But none of these are quite so perfect as the command: `imap jk ` which allows the bigram jk to be typed in rapid succession to simulate the press of Escape.

Not only does this bigram not appear in English words, it is directly on the home row, it’s under two of your strongest fingers, and are as close as they can possibly be (neighbors).

The impressive features unlocked by this physically intuitive and logically disused combination rely, unfortunately, on the completely unintuitive and physically backward layout of Qwerty.

For this reason, changing keyboard layouts to something ideal, like Dvorak, or merely improved like Colemak, breaks access to this bigram and many other Qwerty based (what I refer to as) physical mnemonics, by inflicting upon the user conveniently placed most-used keys and ergonomic comfort. Horror!

When I changed to a custom keyboard layout of my own devising called Julymak, I spent multiple years trying to regain the utility of this bigram for use in Vim and in Emacs within an “Evil” port of Vim.

After many false starts and “good enough” solutions (such as `fp` and `vn`), I believe I’ve finally arrived at the best “good enough” which has applications beyond my keyboard layout.

TL;DR: What’s the new bigram?

The “bigram” is comma period. That is: `,.`

This bigram is unused in English (and in most programming languages), near the home row, under strong fingers, and neighbor keys. Further, it is where your fingers will already be when you type a full stop when writing prose, and it applies to Qwerty, Colemak, and Dvorak.

One could swap to period comma, if the combination felt better mechanically, though it would slow swapping modes after a full stop due to having to type the same key twice which is one of the slowest mechanical forms of typing.

Normally, my discovery of a new escape sequence comes after mounting frustration with the old, but I was pretty happy with `fp` as escape on Julymak, it wasn’t until I was trying to reassign my right home row on my Signum layer 1 that I realized I could just make a jk under my fingers once on layer 1. After experimenting with this, I stumbled into this comma period bigram by mistake, and have taken to it very quickly.

I highly recommend you try it out and report your experience in the comments. Also, please consider the next section:

Lets break some software context!

While looking into this I was playing with QMK with Vial (with which I am extremely impressed), and discovered a complicated scheme of creating a hardware escape key emulated in firmware. In my testing I was able to get the sequence to work well mapping comma to a tap-hold key which produced itself on tap, and moved to another layer, upon which period was escape and space started a macro which sent comma and space. I’m a fast typist and this necessitated some modifications to the tap-hold settings/behaviors/timings.

Unfortunately I found a bug where retro-tapping into a macro shortly after an unrelated keystroke makes QMK think the tap key has been pressed if released before the macro key. This resulted in a delayed comma: `cheese, ,and` and frustratingly only appeared when I built up speed and messed up my flow.

C-C-C-C-COMBO MAKER!

HOWEVER! Combination keys came to my rescue. You can create a combination key irrespective of layers or tap-hold or tap-dance by assigning comma followed by period to produce Escape. The only caveat to this is you must hold down the first key followed by the second… Actually, I just discovered there is no order, they must simply both be held down at the same or close to the same time. This may have other applications I’ll have to look in to!

Obviously a hardware mapping of Escape is only the beginning! Windows has introduced input standards which equate to various Vim functions such as Ctrl+Left jumps a word back, Ctrl+Backspace deletes a word back, and adding shift to control with movements highlights along those same movement paths.

My keyboard runs Vim

Imagine a keyboard that runs a Vim type interface! Pressing b while the keyboard is in normal mode would deliver Ctrl+Left and Ctrl+w while the keyboard is in input mode would deliver Ctrl+Backspace. Obviously there are limits, but minor movements would go a long way toward writing of all kinds, while being platform agnostic, and following you around wherever you take your keyboard! People keep putting vim’s modality and movement into other systems, so why not put it into some hardware!

Best Vim/Evil escape sequence BONUS: Hardware Vim

Leave a comment