72

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;'?

8
  • 4
    Check that Wikipedia page of vi, it contains a picture of some ancient Unix machine keyboard which explains, some keybindings. Commented Aug 23, 2016 at 12:09
  • 3
    Because vim is exempt from keeping up with technological advances :3
    – Alexander
    Commented Aug 23, 2016 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.
    – user1170
    Commented Aug 23, 2016 at 15:48
  • 4
    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
    Commented Aug 23, 2016 at 16:05
  • 2
    BTW, this topic is covered in the second top-voted question on Unix SE Commented Aug 24, 2016 at 11:08

3 Answers 3

87

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

10
  • 32
    This should still be on every keyboard ! :)
    – albttx
    Commented Aug 23, 2016 at 12:12
  • 20
    Now you've got me wondering what kind of terminal the guy who made emacs had...
    – leeand00
    Commented Aug 23, 2016 at 19:09
  • 16
    @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. Commented Aug 23, 2016 at 19:35
  • 12
    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?" Commented Aug 24, 2016 at 14:12
  • 2
    @Carpetsmoker: we didn't invent keyboard arrow location logic until the late 80s upload.wikimedia.org/wikipedia/commons/3/30/… Commented Aug 24, 2016 at 14:37
29

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).

6
  • 1
    Did vi have a <Leader> mapping? I thought that was a later invention... Commented Aug 24, 2016 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
    Commented Aug 24, 2016 at 16:36
  • 1
    It's also hard to find information on vi through google, since most of the results end up being about vim.
    – DJMcMayhem
    Commented Aug 24, 2016 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
    Commented Aug 24, 2016 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
    Commented Aug 24, 2016 at 18:25
19

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:

2
  • 1
    ^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
    Commented Aug 24, 2016 at 10:57
  • Wow I never knew Ctrl-J means linefeed Commented Jul 20, 2023 at 4:04

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