Why use the keys hjkl on the same line instead of keys in a triangle like wasd for moving on video games?

Why not something equivalent with right hand, like ijkl or pl;'?

  • 3
    Check that Wikipedia page of vi, it contains a picture of some ancient Unix machine keyboard which explains, some keybindings. – Christian Brabandt Aug 23 '16 at 12:09
  • 2
    Because vim is exempt from keeping up with technological advances :3 – Alexander Aug 23 '16 at 15:15
  • 3
    You can put four fingers of one hand on the hjkl keys, comfortably, and move the cursor all four directions without shifting fingers back and forth. If you really think about it, four in a row is the only cursor key layout consistent with human anatomy. The question is really how everyone else manages to get it wrong. – Wumpus Q. Wumbley Aug 23 '16 at 15:48
  • 3
    Actually it's not recommended to put your index on the h but rather on the j (that's why you have a "nipple" on the j key). Reason for that is that you will use b much more than h and having ; accessible is handy in a lot of programming language (and with a shift, you have : which is ever more handy in Vim). – nobe4 Aug 23 '16 at 16:05
  • 2
    You know, initially I had voted to close this, since it isn't really a question about how to use vim. However, history-of questions, and questions that aren't directly related to using vim are still on topic, plus it's something I imagine lots of people have wondered. I've certainly wondered this before. I've retracted my CV now. – DJMcMayhem Aug 23 '16 at 16:12
up vote 69 down vote accepted

From http://www.catonmat.net/blog/why-vim-uses-hjkl-as-arrow-keys/:

When Bill Joy created the vi text editor he used the ADM-3A terminal, which had the arrows on hjkl keys. Naturally he reused the same keys and the rest is history!

enter image description here

  • 25
    This should still be on every keyboard ! :) – albttx Aug 23 '16 at 12:12
  • 13
    Now you've got me wondering what kind of terminal the guy who made emacs had... – leeand00 Aug 23 '16 at 19:09
  • 8
    @leeand00: A Symbolics LISP Machine Space Cadet Keyboard. The article explicitly talks about how the design of the keyboard influenced the design of Emacs, and it also compares it to the design of Vi with its ubiquitous Escape key, and the fact that the Escape was very conveniently located on the ADM-3A Terminal's keyboard. Well, on the Space Cadet Keyboard, there are the Control, Meta, Super, and Hyper keys which are very conveniently located, as well no less than 3 different Shift keys allowing to type over 8000 characters. – Jörg W Mittag Aug 23 '16 at 19:35
  • 7
    While this answer is correct as such, it sort of moves the question rather than answer it: "Why did the ADM-3A keyboard choose hjkl and not a more logical shape such as ijkl?" – Martin Tournoij Aug 24 '16 at 14:12
  • 2
    @Carpetsmoker: we didn't invent keyboard arrow location logic until the late 80s upload.wikimedia.org/wikipedia/commons/3/30/… – Jacob Krall Aug 24 '16 at 14:37

Nobe4's answer is great, and explains why we use hjkl very well. However, it's really interesting to see the full keyboard, and a lot of strange things about vim make more sense when you can see the full keyboard it was designed on. For example, why does vi rely so heavily on the esc key, when it's in such a weird and uncomfortable place? This is why:

enter image description here

As you can see, esc is where tab is on most keyboards. ctrl is another key that is slightly awkward to reach, but in a very comfortable location on this keyboard (where caps lock usually is).

  • Did vi have a <Leader> mapping? I thought that was a later invention... – Martin Tournoij Aug 24 '16 at 16:27
  • @Carpetsmoker I think so, but I'm not actually sure. Vim's :help <leader> doesn't have the signature {not in Vi} text, and it does say vi had :map (although not :noremap), so I'm pretty sure that vi had leader. Even if it didn't, I would imagine the history of the vi keyboard would at least somewhat influence the design of vim. – DJMcMayhem Aug 24 '16 at 16:36
  • It's also hard to find information on vi through google, since most of the results end up being about vim. – DJMcMayhem Aug 24 '16 at 16:37
  • @DJMcMayhem pubs.opengroup.org/onlinepubs/009696699/utilities/vi.html and roguelife.org/~fujita/COOKIES/HISTORY/1BSD/exrefm.pdf are good references for vi (POSIX and historical, respectively). You can also download nvi, elvis, vile, or ex-vi (ex-vi is a descendant of the historical vi) and look at what they do or their documentation. There is no <leader> feature in vi. – Random832 Aug 24 '16 at 18:23
  • Also, Vim was originally developed for the Amiga (backslash in its usual [ISO or Large Enter] position), and based on Stevie which was for the Atari ST (backslash in the lower right corner, past enter, but it didn't apparently support :map at all) – Random832 Aug 24 '16 at 18:25

As to why these arrows were printed on these keys... it's because they could be used with the control key for local cursor movement. Ctrl-H and Ctrl-J (backspace and line feed) are obvious, and an easy mnemonic even today. Ctrl-K is "vertical tab", but was sometimes used for reverse linefeed on pre-ANSI terminals. The use of Ctrl-L for a non-destructive cursor forward was probably chosen based on its keyboard location.

You may also have noticed in the picture of the keyboard in the other answer that "HOME" is on the ^/~ key. Of course, Ctrl-^ homes the cursor (sends to the top left of the screen, or bottom left, depending on mode).

These control mappings were also used for Wyse terminals, the Kermit protocol, and were supported in some versions of PC ANSI.SYS.

Sources:

  • ^H, ^K – very enlightening, since today I'll easily remember that ^J moves down. I was never able to remember assignment of up-down reliably. – miroxlav Aug 24 '16 at 10:57

protected by Martin Tournoij Aug 24 '16 at 14:09

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.