History of vi Keys

By Xah Lee. Date: . Last updated: .

How Did Vi's Command Mode and Insert Mode Idea Came About?

Back in 1970s, terminal screen are 80 columns by 24 lines. There's no real-time editing. You edit by typing a command, then call another command to have the screen update to show the result of your command. Vi's “modal editing” is evolved from this. This is also why emacs's manual calls itself “Real Time Display Editor”. Emacs is the first or one of the first “Real Time Display” editor.

The unix text editor vi was originally written by Bill Joy in 1976. Since, there are many clones. vim is currently the most popular, began in 1991.

〔see Keyboard History ⌨

Why vi uses H J K L for cursor movement?

Unix vi's use of H J K L for cursor movement, came from the keyboard it was developed on, the ADM-3A terminal. The keyboard has arrows printed on the H J K L keys.

adm-3a keyboard cb140
ADM-3A keyboard 〔image source https://vintagecomputer.ca/lear-siegler-adm-3a-terminal/

Note the position of the Escape key and the arrows on H J K L, and the position of Ctrl, and position of the colon : key.

vi's choice of Escape key for mode switching, also came from ADM-3A keyboard. It is the most obvious choice on that keyboard.

Why Does ADM 3A Terminal Keyboard Use H J K L for Arrow?

ADM 3A Terminal Manual arrow keys 8WdWX
ADM 3A Terminal Manual arrow keys

〔see ADM-3A Terminal Manual

The reason seems to be part cleverness and part from the design of the ASCII Encoding , which involved a clever assignment of binary code to the letters, and the control characters.

Basically, the binary code for a letter, and its version with Control key held down, differ by 1 bit, and the control held down version of the letters H J K L, happens to be the ASCII non-printable backspace, linefeed, vertical tab, formfeed, and these control characters, happens to be the most apt choice as arrow directions. (there is no dedicated arrow character in ASCII code.)

ASCII Charbackspacelinefeedvertical tabformfeed
decimal8101112
binary00001000000010100000101100001100
Input MethodCtrl+hCtrl+jCtrl+kCtrl+l
ASCII Charhjkl
decimal104106107108
binary01001000010010100100101101001100
ASCII CharHJKL
decimal72747576
binary10001000100010101000101110001100

For example, letter h has binary code

01001000

with Control key held down, it sends the non-printable character Backspace, which has binary code

00001000

and this Backspace character, is most suitable to be considered as left arrow.

The vi designer Bill Joy, simply used the same key in vi, without needing to hold Control key.

Interview with Bill Joy (creator of vi)

HJKL keys and vi

Keybinding and Input-System