TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Here is why vim uses the hjkl keys as arrow keys

478 pointsby freestylerabout 13 years ago

21 comments

jgrahamcabout 13 years ago
Doesn't this go way back though?<p>The reason that keyboard had those arrows keys on it was because those keys correspond to CTRL-H, J, K, L and the CTRL key back then worked by killing bit 6 (and bit 5) of the characters being typed.<p>The effect was that H which is ASCII 0x48 would become 0x08 which is backspace. If you look at an ASCII table (e.g. <a href="http://www.asciitable.com/" rel="nofollow">http://www.asciitable.com/</a>) you will notice how the uppercase ASCII letters line up nicely with the control characters so that just dropping bit 6 will get you there. Same thing with the lowercase (drop bits 5 and 6) and you are on the control characters.<p>The CTRL-H, J, K, L therefore correspond to BS, LF, VT, FF. BS is backspace (i.e. left), LF (down), VT is vertical tab (so up) and FF is form feed (which in this case takes you up). I'm not sure why FF was used for up.<p>This is also why CTRL-I is tab, CTRL-D ends a communication. All of that goes back to teletype days. Also for telnet users out there you'll see that CTRL-[ lines up nicely with ESC. And when you see a ^@ being printed on the terminal you can see why it corresponds to a null byte.<p>One other interesting thing about ASCII: uppercasing and downcasing can be done by twiddling a single bit.<p>If you look at this picture of an ASR-33 Teletype you'll see that come of the control characters on the keyboard correspond to those in the ASCII set. This is because ASCII evolved from the earlier teletype character sets: <a href="http://upload.wikimedia.org/wikipedia/commons/0/0b/ASR-33_2.jpg" rel="nofollow">http://upload.wikimedia.org/wikipedia/commons/0/0b/ASR-33_2....</a>
评论 #3685213 未加载
评论 #3685630 未加载
评论 #3685225 未加载
评论 #3685269 未加载
评论 #3687099 未加载
wavetossedabout 13 years ago
ADM3a was a terminal, not a computer. I used to use these two in around 1976 or so. And the hjkl pattern has nothing to do with this or any other terminal. The ASCII control codes for Ctrl-H, Ctrl-J, Ctrl-K and Ctrl-L were used to make the Teletype's printing carriage move left, down, up or right. Bill Joy's innovation was "modes" so that Ctrl-H did not delete the character when it moved left, etc...
评论 #3687427 未加载
评论 #3694704 未加载
rauljaraabout 13 years ago
Most of the answers I've seen as to why hjkl have fallen into the "so your fingers stay on the home row / it's actually quite fast once you get used to it" realm. But those answers were never completely satisfactory to me. Once you get used to it, it's fine. But I feel like it would have been fine as adsw, or jkl; (so that your hand really is on the home keys) or some other 4 key combination near the home row, too.<p>This explanation of the origin hjkl is the first one to satisfy me. Now I can see the others, not as explanations as to why it is, but explanations as to why it stuck.
评论 #3686670 未加载
评论 #3684781 未加载
评论 #3686366 未加载
评论 #3684748 未加载
ajaysabout 13 years ago
Oh lord! I remember these unibody terminals. I had to use the Volker-Craig VC4404 . That thing was built like a tank. You had to hammer at the keys with great force. Soon one got into the habit of hammering on the keys all the time.<p>And then one day I walked into the lab with shiny new VT-100 terminals with their soft keys; but started hammering on them by habit. And everybody turned around and looked at me as if I was possessed..... :-D
评论 #3684844 未加载
评论 #3693477 未加载
pigsabout 13 years ago
Perhaps just as enlightening is the location of the Esc key (to the left of Q): <a href="http://en.wikipedia.org/wiki/File:KB_Terminal_ADM3A.svg" rel="nofollow">http://en.wikipedia.org/wiki/File:KB_Terminal_ADM3A.svg</a>
评论 #3684669 未加载
robtooabout 13 years ago
It would have been a lot more useful if the link had said how/why the ADM-3A used <i>hjkl</i> as cursor keys.
评论 #3684661 未加载
评论 #3684664 未加载
ldhabout 13 years ago
I worry that the tone of the article seems dismissive of the choice that went into mapping those keys to arrow directions in vi ("That's the whole story"). As if to say it was mere happenstance that vi uses hjkl, and any other outcome was equally likely.<p>It seems more the case that the designers of that computer chose those particular keys on the basis of a desire for efficiency that vi also followed, so there was no need to create a new convention.
评论 #3684663 未加载
jffabout 13 years ago
I've got one of those sitting in my spare room... I'd be using it right now were it not for a busted flyback, which emits a whine capable of giving me a headache within 15 minutes. It's really a rather nice terminal, with an oddly attractive screen font and a keyboard that is well-suited to UNIX.<p>The coolest part is that there is no microprocessor, just a bunch of 7400 series ICs and some DIP switches to configure things.
ehsanu1about 13 years ago
If anyone is apprehensive about vim's hjkl keys, and you like the arrow keys better, you can use ijkl instead and get all the benefits of the muscle memory you have built up for arrow keys, while still keeping your hands on the home row. Use this mapping:<p><pre><code> " remap h to i and use ijkl for inverse T cursor movement map k g&#60;Down&#62; map i g&#60;Up&#62; map j &#60;Left&#62; noremap h i </code></pre> Then the 'i' key will be replaced by 'h'. So press 'h' to insert, or for inner selections, instead of 'i'. Also note the 'g' for up/down motions, which means it won't skip the wrapped part of lines - just remove the 'g' if you don't like that.<p>If you're worried this breaks anything else, I've had this interfere with just one other thing: a plugin that let me select text based on indentation of the line the cursor was on, but I made a few minor changes to the vimfile for the plugin and fixed that pretty easily. The other thing is that random servers won't have these mapped, but just copy the config over if you'll be doing a lot of text editing on that server. Otherwise, you can just fall back to using hjkl awkwardly.
评论 #3685228 未加载
评论 #3685593 未加载
pacoverdiabout 13 years ago
Another reason to use HJKL is that over a 1200bauds line, it is faster to send a single byte than the 3 bytes generated by the arrow keys (^[[D^[[A^[[B^[[C)
评论 #3687257 未加载
ajrossabout 13 years ago
The ADM-3A was a dumb terminal (well, it had to have had some level of screen addressibility, but was definitely not ANSI-compatible), not a computer. They were sold as kits, and about 1/3 the price of a VT-100. I remember reading somewhere that they were the first glass teletypes available to the BSD folks, and Bill Joy wrote vi purely because it allowed him to monopolize one for his own use.
评论 #3694733 未加载
ef4about 13 years ago
You will find similar reasons for why Emacs chose many of its common keys if you examine the [Space Cadet keyboard](<a href="http://en.wikipedia.org/wiki/Space-cadet_keyboard" rel="nofollow">http://en.wikipedia.org/wiki/Space-cadet_keyboard</a>) for which it was designed.<p>All those awkward Control reaches originally laid comfortably under the thumbs.
afterburnerabout 13 years ago
So, since the vast majority of users didn't start out on that keyboard, the reason to keep doing it that way now is: tradition.
hallnoatesabout 13 years ago
This feature of vi/vim along with not being able to save and quit as quickly as I can in emacs (ctrl-s ctrl-x, baby, none of that :q! shite) is the reason I use emacs. I totally respect those that use vim, but I'm not a freaking machine.
评论 #3685984 未加载
评论 #3686284 未加载
评论 #3687483 未加载
SkyMarshalabout 13 years ago
I'm actually glad it worked out that way, I hate using the regular, out-of-the-way arrow keys. They're even more annoying than the mouse.
评论 #3684741 未加载
truncateabout 13 years ago
I'm used to H, J, K, L now. But when I wasn't aware of the history of vi, I always wondered why on earth he didn't use J, I, K, L!
dansoabout 13 years ago
I wonder if being right-handed also affected that choice...either the vim implementation or the hjkl keys as arrow keys.
saddinoabout 13 years ago
Wait, I thought Rogue popularized hjkl? ;-)
phzbOxabout 13 years ago
Wow, thanks for sharing this. I really thought it was for efficiency. (Well, it is also, obviously).
rabidsnailabout 13 years ago
That is the coolest looking thing with a keyboard I've ever seen. I want one.
artursapekabout 13 years ago
That's a pretty sexy terminal.