6 ms·
Here is why vim uses the hjkl keys as arrow keys
- ajays 15y agoOh 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. 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
- godfreykfc 15y agoI smiled when I saw how you call them "unibody" terminals. We have come a long way since then. :)
- petdance 15y agoWhen my dad bought a DEC Rainbow 100, I loved loved loved that I could move the keyboard. Such a boon!
- boldt 15y agoHere's a VC4404 manual which shows the key layout/functions: http://vt100.net/volker-craig/vc4404-um.pdf http://vt100.net/volker-craig/vc4404-um.pdf
- phzbOx 15y agoWow, thanks for sharing this. I really thought it was for efficiency. (Well, it is also, obviously).
- ldh 15y agoI 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. 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.
- jh3 15y agoThe "article" is barely three full sentence and includes two images. To me it clearly states why hjkl were chosen as the keys for navigating around the editor. How does the author's "That's the whole story!" ending make you feel like he's saying hjkl being used as the navigation keys was a coincidence?
- ldh 15y agoHonestly perhaps it's partly a defensive reaction about a tool I like. If so, my bad. Maybe I can't help but feel like the "article" could be perceived as saying "see, vim chose these keys simply because that's what the keyboard said without any thought toward efficiency". The idea that they're chosen for efficiency seems so self-evident that it doesn't need a flourish to reveal. It's likely I'm thinking too hard about it. In any case, it is a neat little bit of history and the link gets my upvote.
- bmj 15y agoMaybe "efficiency" is implied, since folks using the initial version of vi would be used to using those keys for navigation anyway. So, I read this more as "Bill Joy used a convention" rather than "Bill Joy chose the most efficient keys for touch typists."
- ajross 15y agoThe 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.
- kragen 15y agoYes, in addition to the cursor movement control characters, there was a single escape sequence for moving to a specified row and column. I didn't know they were sold as kits. Did you buy a kit?
- pigs 15y agoPerhaps just as enlightening is the location of the Esc key (to the left of Q): http://en.wikipedia.org/wiki/File:KB_Terminal_ADM3A.svg http://en.wikipedia.org/wiki/File:KB_Terminal_ADM3A.svg
- joshmlewis 15y agoI'm just learning vim and just yesterday I was wondering why they chose the escape key.
- shabble 15y agoThese days I mostly use Ctrl-C instead of Esc, just because it's so much easier to type. If you make a serious commitment to vi(m) though, binding your capslock to esc is probably the better way to go.
- graywh 15y agoI found ctrl there more useful. Especially for its use with other programs.
- deleted 15y ago[deleted]
- robtoo 15y agoIt would have been a lot more useful if the link had said how/why the ADM-3A used hjkl as cursor keys.
- ImprovedSilence 15y agoFor those reading this that don't know, it's so your hands stay on the "home row" [Edit:] or at least that's what I thought, wavetossed's comment below provides interesting insight.
- kprobst 15y agoProbably because it didn't have dedicated arrow keys. Many older terminal keyboards didn't.
- gojomo 15y agoBut why did the terminal choose those keys? Most games have chosen an up-down combo that are up-down from each other, rather than right-left. The thing about ASCII Control characters doesn't quite map to left-up-down-right, and even if it were part of the answer, we could ask again: why were those characters chosen for those control-roles?
- hallnoates 15y agoAnd the reason they didn't was that they evolved from typewriters that relied on a forward/backward spin to move up and down (except for the carriage return lever). We're lucky that the original terminals didn't have a scroll knob on the left and right of the machine to move up and down and a lever to move to the next line or we would have been stuck with that concept for years and the laptop may not have been invented because the knobs and lever would have required some elevation, which means the whole thing would have had to have been bigger.
- wavetossed 15y agoADM3a 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...
- fanf2 15y ago8 H backspace 9 I tab (right a lot) 10 J line feed (down) 11 K vertical tab (down a lot) 12 L form feed (down a page) 13 M carriage return (left a line)
- kragen 15y agoBill Joy didn't invent modes; all editors were very modeful until Bravo, in the 1970s. And in vi, you don't use ^H to move left; you use h. Tony has already corrected you on ^K and ^L, but I'll point out that there was a way to move the carriage right on a Teletype, even though it wasn't ^L: the SPACE character does that.
- danso 15y agoI wonder if being right-handed also affected that choice...either the vim implementation or the hjkl keys as arrow keys.
- SkyMarshal 15y agoI'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.
- eru 15y agoJust never decide to learn dvorak.
- dkersten 15y agoAgreed, learn Colemak instead ;-) Seriously though, I think with a tiny bit of key-swapping in the vimrc, you can use dvorak or colemak just fine.
- SkyMarshal 15y ago+1. Dvorak needs to go the way of the dodo. Colemak:Dvorak::Dvorak:Qwerty. http://colemak.com/ http://colemak.com/
- dkersten 15y agoI love colemak. While I'm still not quite as fast as I once was with qwerty, it does seem to take less effort and my fingers seem to dance over the keys as most key combos do really seem to be placed side-by-side.
- finnw 15y agoI use dvorak with vim with (mostly) standard key bindings. It's not too bad. H and K are not far from their respective QWERTY positions. J and K remain next to each other.
- mrb 15y agoTip from a dvorak vim user: instead of H/L for moving left/right, use H/SPACE. SPACE has almost the same function as L but is more convenient to hit with your thumb. SPACE also allows moving to the next line when the cursor it at the end of a line, unlike L.
- rauljara 15y agoMost 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. 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.
- cheatercheater 15y agoI have created an ergonomic layout based on the us layout, called us_split. In it, Vim's hjkl actually are the home position. The layout works under Gnome. It's just like qwerty but a bit different. Basically the two columns from the right are put in the middle. Time to learn to use it fluently is only a couple of days if you touch type qwerty already. https://bitbucket.org/cheater/us_split/overview https://bitbucket.org/cheater/us_split/overview I see a lot of people in the comments talk about vim's "weird" layout choices. I suggest in your OS you change caps lock to esc; and that in vim you remap ; to : and : to ; in order to stop having to press shift every time. You can then really start doing the whole home row thing; IMO it's impossible without those two crucial settings.
- bryanlarsen 15y agoThat's a brilliant layout. Unfortunately it appears to require a "tall enter" keyboard rather than the much more common "wide enter". I'm in the market for a nice cherry blue keyboard, so I'll see if I can find one with a tall enter. Anybody have any sources?
- dkersten 15y agoI'm using the silent ([EDIT: I had this in reverse..] cherry mx brown; non silent is cherry mx blue) DAS keyboard[1]. The "professional" model has the letters on the keys, if you don't want a blank one. They seem to come in both US (wide enter) and UK (tall enter) versions. I personally chose the UK one as that's what I'm used to. Here[2] is a photo of my keyboard. The coloured keys are sold as WASD/escape keys but I used them for playing Skyrim - the green one on the right is especially handy for gaming as i don't have my fingers on the home row when playing games rather than typing. The blurred circuit board is a development version of the Midifighter 3D[3] as the photo was taken before they were announced. [1] http://www.daskeyboard.com/model-s-ultimate-silent/ http://www.daskeyboard.com/model-s-ultimate-silent/ [2] https://plus.google.com/u/0/photos/100355674716107842386/albums/posts/5676123139988463922 https://plus.google.com/u/0/photos/100355674716107842386/alb... [3] http://www.djtechtools.com/2012/02/27/introducing-the-midi-fighter-3d/ http://www.djtechtools.com/2012/02/27/introducing-the-midi-f...
- artursapek 15y agoThat's a pretty sexy terminal.
- jgrahamc 15y agoDoesn't this go way back though? 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. The effect was that H which is ASCII 0x48 would become 0x08 which is backspace. If you look at an ASCII table (e.g. http://www.asciitable.com/ http://www.asciitable.com/) 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. 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. 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. One other interesting thing about ASCII: uppercasing and downcasing can be done by twiddling a single bit. 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: http://upload.wikimedia.org/wikipedia/commons/0/0b/ASR-33_2.jpg http://upload.wikimedia.org/wikipedia/commons/0/0b/ASR-33_2....
- ChuckMcM 15y agoThis is correct, and the reason they used those keys was that it was the 'home row' on a typewriter which was used in teletypes which meant your little finger could push 'ctrl' and your right hand could drive the cursor through forms without moving off the home row. When I saw the title I was expecting to see a picture of the rogue screen. Rogue (and later hack, and nethack) is a text displayed dungeon exploration game and was often the first exposure folks got to the convention of h,j,k,l as left right up down. I really miss having control over there. I xkeymap it there of course but some keyboards have a physically 'push-on/push-off' caps lock key there which is annoying.
- kickingvegas 15y agoCount me in the school of thought that the control key is meant to be to the left of the A key, just like the horn button is meant to be in the center of a car steering wheel. Every computer keyboard I worked with before the advent of IBM PCs had this arrangement. Every computer I work with now I reconfigure to swap the caps lock with the control key. IT IS THE NATURAL ORDER OF THINGS.
- saddino 15y agoWait, I thought Rogue popularized hjkl? ;-)
- ef4 15y agoYou will find similar reasons for why Emacs chose many of its common keys if you examine the [Space Cadet keyboard](http://en.wikipedia.org/wiki/Space-cadet_keyboard http://en.wikipedia.org/wiki/Space-cadet_keyboard) for which it was designed. All those awkward Control reaches originally laid comfortably under the thumbs.
- afterburner 15y agoSo, since the vast majority of users didn't start out on that keyboard, the reason to keep doing it that way now is: tradition.
- jff 15y agoI'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. The coolest part is that there is no microprocessor, just a bunch of 7400 series ICs and some DIP switches to configure things.
- ehsanu1 15y agoIf 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: " remap h to i and use ijkl for inverse T cursor movement map k g<Down> map i g<Up> map j <Left> noremap h i 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. 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.
- sciurus 15y agoI'd recommend the opposite. If you're apprehensive about hjkl, force yourself to use it anyway! " disable arrow keys nnoremap <Up> <nop> nnoremap <Down> <nop> nnoremap <Left> <nop> nnoremap <Right> <nop>
- ehsanu1 15y agoI didn't advocate using arrow keys, but rather using ijkl. Your suggestion is not mutually exclusive with my own, you can do both. :) Though I guess the mappings I provided would have to be noremap instead of map.
- graywh 15y agoI'd recommend specifying a mode on those. That i map disables half the text-objects in visual and operator modes.
- ehsanu1 15y agoI still use those text-objects, just with h instead of i. This is required because otherwise, you'll have issues when trying to move in visual and other modes.
- pacoverdi 15y agoAnother 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)
- housel 15y agoThe ADM3A was a "dumb" terminal, constructed using a board full of 7400-series TTL ICs with no microcontroller. Probably to simplify the design, it wasn't capable of sending any multi-character escape sequences. (The ANSI escape sequences hadn't been standardized at that point yet either.)
- hallnoates 15y agoThis 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.
- ghostwords 15y agoTo save with [Esc],w add the following to your ~/.vimrc " remap <Leader> to , let mapleader = "," " save with ,w nmap <Leader>w :w<CR>
- mgedmin 15y agoI can hit ZZ faster than ctrl-x ctrl-s ;)
- wazoox 15y ago:x or ZZ instead of :wq wins :)
- rabidsnail 15y agoThat is the coolest looking thing with a keyboard I've ever seen. I want one.
- truncate 15y agoI'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!