This is part of the talk “UNIX archeology” I gave at OpenFest 2023.

If you, dear reader, are a vim user, you’ve probably seen this keyboard:

ADM-3A keyboard

It explains a lot about our beloved text-editor. CTRL is just where it has to be in the first place, the Esc is so near and the : symbol we use for commands is not hidden behind a modifier like nowadays. But why the arrows?

So, one might say: “Well, because Bill Joy created vi using this ADM-3A terminal where the arrows just happened to be located there”. And that person would be absolutely right. But why were they located there?

To be fair, if you look at other terminals from these days, where to put the arrows was not really standardized. Not even the triangular shape, we’re so used with today. Most machines would put them in one line, but in different order. For instance, some would go with [↓] [↑] [←] [→]. So far, the answer that they just had to put them somewhere still holds.

ASCII

It was not random, though. You see, in ASCII characters are not just put at some point on random. There are fairly good decisions taken there that go mostly unnoticed today as people no longer work directly with ones and zeroes really. If you want to get the code for an upper-case letter you should add 64 to the position of that letter in the alphabet. If you want it to be lower-case, add 96 instead. That’s pretty clever, because it all boils down to flipping a bit:

ASCII Char H [←] J [↓] K [↑] L [→]
Decimal 72 74 75 76
Binary 01001000 01001010 01001011 01001100
ASCII Char h [←] j [↓] k [↑] l [→]
Decimal 104 106 107 108
Binary 01101000 01101010 01101011 01101100

This first bit is always 0, as ASCII is a 7-bit character set. If the second bit is up, we are dealing with a letter. If the third is up, then this letter is a lower-case. It’s that simple. But look what happens if we set both of those 2nd and 3rd bits to zero:

ASCII Char Backspace Linefeed Vertical Tab Formfeed
Decimal 8 10 11 12
Binary 00001000 00001010 00001011 00001100

When pressing any of those four keys, the terminal has to take two decisions:

  • If [Shift] is pressed, set the 3rd bit to 0
  • If [CTRL] is pressed, set the 2nd and 3rd bits to 0

But wait, there’s more

Legacy we still observe from this terminal doesn’t end here, though.

~/

Take a look at the top right button. Yep. That’s why we are shortening the path to user’s home folder as ~/.

Regular expressions

If you ever wondered why ^ is the beginning of line or “home” position in regular expression dialects, well… now you know :)