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

VimKey Bindings

Vim Problem Overview


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?

Vim Solutions


Solution 1 - Vim

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

Here's the keyboard layout:

Enter image description here

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.

Solution 2 - Vim

vimtutor provides the mnemonic that 'J' looks vaguely like a downward-pointing arrow, though that may or may not be the original reason why it was chosen.

Solution 3 - Vim

This is a total guess, but: The Ctrl+J character is the "line feed" character, which on a traditional TTY moves down one line, providing a mnemonic. K was right next to it on a Qwerty keyboard, under the second most commonly used finger on the right hand when in the home position.

Solution 4 - Vim

From a user experience perspective, after you open a file, you always move down first and moving down is usually a more frequent operation. Since from left to right is the natural direction for most of us, it make sense to associate the task you perform first or more frequently with the key on the left. You can try to switch the 2 keys and try to tell which way is better. For me, "J" for down is more natural and comfortable.

Solution 5 - Vim

It explains it if you run vimtutor in the terminal. It says:

> The h key is at the left and moves left. > > The l key is at the right and moves right. > > The j key looks like a down arrow.

Solution 6 - Vim

Simply to supplement all the answers, here is the photo of the ADM-3A keyboard (the exact keyboard on which Vim has been created).

P.S: I wish they had used W, A, S, D

Enter image description here

Solution 7 - Vim

I always thought it was because on the Dvorak layout, j and k are also next to each other. There are not many keys that have this property on both Dvorak and A/QWERTY/Z.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiongeowa4View Question on Stackoverflow
Solution 1 - Vimmartin claytonView Answer on Stackoverflow
Solution 2 - VimjwodderView Answer on Stackoverflow
Solution 3 - VimGreg HewgillView Answer on Stackoverflow
Solution 4 - VimsunquanView Answer on Stackoverflow
Solution 5 - VimAskYousView Answer on Stackoverflow
Solution 6 - VimVirtual DeviceView Answer on Stackoverflow
Solution 7 - VimSjaak BanaanView Answer on Stackoverflow