Search code examples
vimkey-bindings

In Vim, why is 'j' used for down and 'k' for up?


I've been using Vim for many years and have never really thought about it. A friend of mine asked why that is, noting that in our culture, left would usually map to up while right would map to down, making the Vim keys backwards.

I understand that they are on the home row, meaning that you do not have to move your fingers anywhere to hit them, but that's a different point altogether.

Why were these keys given their present purposes? Is there some documentation on the decision as well?


Solution

  • The answer is in the Wikipedia entry for vi. Bill Joy, who wrote the visual mode of ex - which ended up being Vim's precursor vi - used a Lear Siegler ADM-3A terminal on which the HJKL keys mapped to left, down, up, right - and it’s been that way ever since.

    Here's the keyboard layout:

    keyboard layout of the ADM-3A

    A couple of other points of note on the ADM-3A layout:

    • Left of the Q: the escape key - somewhat handier than where it is on keyboards today, hence a good choice for switching between normal and insert modes.
    • Top right: the 'Home' key doubles as the tilde (~), which subsequently became shorthand for a Unix user's home directory.