81

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?

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
geowa4
  • 40,390
  • 17
  • 88
  • 107
  • 5
    To quote Crockford, "It seems like once something stupid gets in, it takes a long, long time to get it out." :-) http://developer.yahoo.com/yui/theater/video.php?v=crockonjs-2 – Courtney Christensen Jul 01 '11 at 22:30
  • 5
    Why in your opinion does left usually map to up and right to down. I haven't really thought of it before but I *feel* it should be the otherway around. Possibly purely because I'm right-handed (but the majority of us are) and so, maybe something like, right feels more positive, as does up. Hmm. I'm just intrigued why your natural reaction is to see it the other way. This certainly isn't the place for this discussion though (I wonder where is, psychology.stackexchange maybe - if such a place exists). – tjm Jul 01 '11 at 22:30
  • 4
    @tjm, I agree that "right feels down" in the sense that we read left-to-right. Once you're at the end of a line, the next character is always 'down'...Just a thought. Anyone whose native language reads right-to-left out there feel differently? – Courtney Christensen Jul 01 '11 at 22:32
  • When using the Latin alphabet the text starts at the top left corner of the page. I feel it would be more intuitive to have the 'j' key pointing up. This would have the left directional keys ('h' and 'j') taking us back toward the 'beginning' of the page, and the right keys taking us to the 'end'. – onewhaleid Oct 02 '14 at 00:38
  • 2
    Sorry for responding to such an old thread, but I believe the reason j feels like it should be up is twofold. 1) Your middle finger rests on j which, for the vast majority of people is your longest finger, and therefore points 'up' more than the others. 2) Most people are used to using the cursor keys, which have up and down arranged one above the other, meaning that unless you do some kind of finger acrobatics, the middle finger acts as both up and down, so when you then use your 4th finger to go up it just feels plain weird. – DRendar Mar 30 '17 at 17:12
  • I sometimes imagine k as the gas pedal, which moves me forward; and j as the brake, which pulls me back :) Though after all the years, sometimes my logic gets confused. Why the left side opening braces [ and { are associated with upwards movements (as in "the text before"), when the left side j moves me down? – Halil Özgür Dec 26 '19 at 16:33

7 Answers7

106

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.
Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
martin clayton
  • 76,436
  • 32
  • 213
  • 198
  • 3
    ah crap. you beat me by a minute. – abcd Jul 01 '11 at 22:39
  • 63
    well now i guess the question is why did the ADM3A use J for down. – geowa4 Jul 01 '11 at 22:47
  • 1
    I wish they would just remove caps lock, finally. – Neil G Jul 02 '11 at 03:17
  • 19
    @geowa4, J was probably down because Ctrl+J is line feed in ASCII. The ADM3A terminal was just barely smarter than a teletype, so a coincidence like that might have simplified something in the implementation. Note that Ctrl+H is ASCII backspace which corresponds to left... – RBerteig Jul 02 '11 at 09:48
  • I've seen some people advise to remap the caps lock key as escape to get that ease of use back :) – Jack Simpson Jun 30 '15 at 03:59
  • @NeilG and replace it with `Esc` – Kellen Stuart Sep 01 '18 at 04:42
  • `vi` was originally a *wrapper* around `ex` - `ex` was still a stand-alone command. As for `vim`, if you create a symbolic link from `vim` to `ex` (if it's not already there), you can use it to make `vim` emulate `ex`. – Baard Kopperud Mar 07 '21 at 01:26
25

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.

jwodder
  • 54,758
  • 12
  • 108
  • 124
  • 20
    An alternative mnemonic is that `j` has a [descender](http://en.wikipedia.org/wiki/Descender) while `k` has an [ascender](http://en.wikipedia.org/wiki/Ascender_(typography)). – hammar Jul 04 '11 at 00:08
  • if you read a paragraph, H goes "back" towards what you have already read, and L goes towards what comes next, so I find J should still go "back", up one line. – ecoologic Nov 23 '21 at 05:16
15

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.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • a plausible intentional coincidence w.r.t. the design of the aforementioned ADM3A terminal layout – interestedparty333 Jun 23 '20 at 23:01
  • The calculation may be something like [ASCII 74](https://en.wikipedia.org/wiki/ASCII#Printable_characters) (J) - 64 (Ctrl) = [ASCII 10](https://en.wikipedia.org/wiki/ASCII#Control_code_chart) (LF / Line Feed). – Peter Mortensen Apr 08 '22 at 20:35
3

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Virtual Device
  • 1,650
  • 3
  • 10
  • 26
2

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.

sunquan
  • 322
  • 3
  • 9
  • 1
    "make the down key come first before the up key" I'm not sure what you mean by "come first before" as I don't see a sense of direction in the keyboard, but I think we agree that hitting a key with the index finger is easier than with the middle finger. So it makes sense to use the key that's nearly always under the index finger for down, the most common direction to navigate in a file. – JoL Apr 27 '17 at 16:40
  • @jlmg For me, if A is **on the left** of B, it feel nature to say that A comes first and B comes later. And I will prefer put the key I press **first** and **more frequently** on the left hand rather on the right. It's just more natural and comfortable for me. – sunquan Apr 28 '17 at 18:48
2

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.

Community
  • 1
  • 1
AskYous
  • 4,332
  • 9
  • 46
  • 82
1

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • The question is actually about **why using J for down and K for up** (why not K for down?) in such layout. – sunquan Apr 28 '17 at 18:54