
Here is why vim uses the hjkl keys as arrow keys - freestyler
http://www.catonmat.net/blog/why-vim-uses-hjkl-as-arrow-keys/
======
jgrahamc
Doesn'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/>)
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....](http://upload.wikimedia.org/wikipedia/commons/0/0b/ASR-33_2.jpg)

~~~
ChuckMcM
This 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
Count 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.

~~~
mickeyp
It's a major frustration for me, too, as an Emacs user.

I'm still looking for a hardware dongle that does nothing but map the caps
lock scan code to left ctrl. Sure, I can rebind the key (and I do) but as a
contractor I move around a lot and having something that circumvents the OS
entirely would come in handy.

~~~
angusangus
I use a keyboard that has a similar layout to that in the images above (ctrl
to left of A, tilde on home key at top right etc). It's called the Happy
Hacking Keyboard and is made in Japan by a Fujitsu subsidiary: see here
<http://en.wikipedia.org/wiki/Happy_Hacking_Keyboard>. It's extremely
expensive (~$300 or so) but has amazing key action and having gotten used to
it I would never want to use anything else

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

~~~
fanf2

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

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

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.

~~~
TheEzEzz
I use JKLI. The two main advantages are that you don't use your pinky finger
repetitively, and the layout of JKLI makes intuitive sense as to what each key
does.

~~~
karamazov
Once you get used to hjkl,it's pretty "intuitive" (in that you don't need to
think about what you're doing).

~~~
nirvdrum
Unless you use Dvorak. I know I'm in a super minority here. But shortcuts
based on keyboard location rather than tied to some mnemonic are damn near
impossible to get right. Doubly so when I have to switch to QWERTY to work
with anyone else.

~~~
hyperbovine
I switched cold turkey to Dvorak and Vim at practically the same time (what
can I say, I like pain :) I learned Vim mnemonically and have no problem using
Vim on QWERTY. At the same time, I could have just as easily learned it
"locationally" and been screwed. Only chiming in because I think it's
interesting that the learning curves for location-vs-mnemonic seem
approximately equal, but the long-term payoff of one is much greater. Neat
asymmetry.

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

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
I smiled when I saw how you call them "unibody" terminals. We have come a long
way since then. :)

~~~
petdance
When my dad bought a DEC Rainbow 100, I loved loved loved that I could move
the keyboard. Such a boon!

------
pigs
Perhaps 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>

~~~
joshmlewis
I'm just learning vim and just yesterday I was wondering why they chose the
escape key.

~~~
shabble
These 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
I found ctrl there more useful. Especially for its use with other programs.

------
robtoo
It would have been a lot more useful if the link had said how/why the ADM-3A
used _hjkl_ as cursor keys.

~~~
ImprovedSilence
For 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.

~~~
keporahg
Then wouldn't have 'jkl;' made more sense? (assuming index fingers were placed
on 'f' and 'j' back then as well)

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

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
The "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
Honestly 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
Maybe "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."

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

The coolest part is that there is no microprocessor, just a bunch of 7400
series ICs and some DIP switches to configure things.

------
ehsanu1
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:

    
    
        " 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
I'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
I 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.

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

~~~
housel
The 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.)

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

~~~
kragen
Yes, 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?

------
ef4
You 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>) for which it was designed.

All those awkward Control reaches originally laid comfortably under the
thumbs.

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

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

~~~
ghostwords
To save with [Esc],w add the following to your ~/.vimrc

    
    
      " remap <Leader> to ,
      let mapleader = ","
    
      " save with ,w
      nmap <Leader>w :w<CR>

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

~~~
eru
Just never decide to learn dvorak.

~~~
jff
This is good advice in all situations, having watched my bandwagon-jumping
friends flail helplessly when using anyone else's computer. And all for a
small potential increase in speed, at the cost of making your computer
unusable to others and completely screwing the convenience of most keyboard
shortcuts.

~~~
eru
> at the cost of making your computer unusable to others

I have a qwerty guest keyboard next to my Kinesis Advantage. Also dvorak isn't
necessarily that faster, but rather more comfortable.

------
truncate
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!

------
danso
I wonder if being right-handed also affected that choice...either the vim
implementation or the hjkl keys as arrow keys.

------
saddino
Wait, I thought Rogue popularized hjkl? ;-)

------
phzbOx
Wow, thanks for sharing this. I really thought it was for efficiency. (Well,
it is also, obviously).

------
rabidsnail
That is the coolest looking thing with a keyboard I've ever seen. I want one.

------
artursapek
That's a pretty sexy terminal.

