News for hackers. Stuff that matters.
Re:Writing an editor in less than 1000 lines of code, just f... by savanaly on Sunday July 10, 2016 @02:17PM (#12066536)
Presumably h, j, k, l will always get you around in vi?
Re:Writing an editor in less than 1000 lines of code, just f... by IshKebab on Sunday July 10, 2016 @03:05PM (#12066752)
Yeah but that is so much less usable. Quick, which one is up?
Re:Writing an editor in less than 1000 lines of code, just f... by Someone on Sunday July 10, 2016 @03:31PM (#12066880)
Just look at your keyboard :-)

(https://en.m.wikipedia.org/wiki/ADM-3A#Legacy)

I always try to remember them by noting that the leftmost key moves left, the rightmost key moves right (not too hard), and that 'K climbs' (using alliteration to remember that). That leaves 'J' for cursor down.

In practice, though, I use the cursor keys. Luckily, they work on the editors/systems I work on nowadays. Side effect is that I am very bad at remembering those mnemonics.

Re:Writing an editor in less than 1000 lines of code, just f... by robgough on Sunday July 10, 2016 @04:57PM (#12067235)
I stole the following from a colleagues `.vimrc` which finally allowed me to learn `hjkl`. Now I forget I have this set, and when I do accidentally use an arrow key it makes me laugh.

    map <Left> :echo 'damnit!'<cr>
    map <Right> :echo 'you suck!'<cr>
    map <Up> :echo 'this is why you fail'<cr>
    map <Down> :echo 'nooooo!'<cr>
Re:Writing an editor in less than 1000 lines of code, just f... by repsilat on Monday July 11, 2016 @01:58AM (#12069148)
> K climbs

Lower-case 'k' has an ascender, lower-case 'j' has a descender.

https://en.wikipedia.org/wiki/Ascender_(typography) https://en.wikipedia.org/wiki/Descender

Re:Writing an editor in less than 1000 lines of code, just f... by somethingsimple on Sunday July 10, 2016 @08:49PM (#12068119)
Off-topic: I love your username. See https://news.ycombinator.com/item?id=12068116
Re:Writing an editor in less than 1000 lines of code, just f... by daveguy on Sunday July 10, 2016 @04:21PM (#12067107)
The point is, they are no longer in symbolic memory. At this point they are muscle memory. Quick, which muscle do you use to move your right thumb in? Does it matter?
Re:Writing an editor in less than 1000 lines of code, just f... by cantrevealname on Sunday July 10, 2016 @04:49PM (#12067207)
Exactly: muscle memory. In your car, do you move the turn signal lever up or down to indicate a right turn? It actually takes longer to answer this question than to do the action in real life.

Another example: There are several passwords that I can type instantly, but I wouldn't be able to recite them.

Re:Writing an editor in less than 1000 lines of code, just f... by fennecfoxen on Sunday July 10, 2016 @05:54PM (#12067437)
> In your car, do you move the turn signal lever up or down to indicate a right turn?

You rotate it the same direction you're about to rotate the wheel. The vi navigation keys have no such convenient correspondence.

Re:Writing an editor in less than 1000 lines of code, just f... by tubs on Monday July 11, 2016 @03:18AM (#12069378)
h is left because it is on the left of the movement keys, l is right because it is on the right of the movement keys... a fairly convenient correspondence.
Re:Writing an editor in less than 1000 lines of code, just f... by JetSpiegel on Sunday July 10, 2016 @06:41PM (#12067621)
The J kinda looks like an arrow pointing down. If you squint.
Re:Writing an editor in less than 1000 lines of code, just f... by somethingsimple on Sunday July 10, 2016 @08:48PM (#12068116)
I also like what Someone (literally their username, lol) pointed out on another comment, that you can think of K as "klimb" to move up.
Re:Writing an editor in less than 1000 lines of code, just f... by __s on Monday July 11, 2016 @08:32AM (#12070562)
Just have to imagine the motion. I remember left/right by literally right clicking & feeling my middle finger be to the right of my index. I got a little mixed up when I switched my mouse to my left hand
Re:Writing an editor in less than 1000 lines of code, just f... by asksol on Sunday July 10, 2016 @04:15PM (#12067087)
I use hjkl consistently in vim and in the shell. Just think about how long it takes you to move your fingers to the cursor keys. You should spend some effort getting used to it, as using hjkl means you can keep your hands in the middle of the keyboard. I have also never had any problems with strain, and I suspect this is part of the reason.
Re:Writing an editor in less than 1000 lines of code, just f... by Narishma on Monday July 11, 2016 @01:38AM (#12069100)
How do you use them in the shell?
Re:Writing an editor in less than 1000 lines of code, just f... by lloeki on Monday July 11, 2016 @03:19AM (#12069383)

    set -o vi           # bash
    bindkey -v          # zsh
    set editing-mode vi # ~/.inputrc i.e readline
Re:Writing an editor in less than 1000 lines of code, just f... by dozzie on Sunday July 10, 2016 @03:53PM (#12066999)
"k", as "k" glyph reaches higher from the two. And conversely, "j" reaches lower, so it moves down.
Re:Writing an editor in less than 1000 lines of code, just f... by IshKebab on Monday July 11, 2016 @07:17AM (#12070267)
You're right, that is much more usable than having an up button in the up position with an up arrow on it...
Re:Writing an editor in less than 1000 lines of code, just f... by dozzie on Monday July 11, 2016 @08:15AM (#12070476)
Erm... what? I didn't claim it's more usable (though it is for me). I just provided mnemonics I saw once which I liked, for a question "which k/j moves up and which moves down?".
Re:Writing an editor in less than 1000 lines of code, just f... by jholman on Sunday July 10, 2016 @06:05PM (#12067475)
The leftmost one is left, the rightmost one is right. Of the two that remain, the one that looks vaguely like an arrow pointing downward, that one goes down. There's one key remaining, and that one goes up, k?

As everyone says, it doesn't take a lot of practice before you know it well enough that you'll never forget. Unbind the arrow keys, or go play some nethack (no-keypad), or whatever.

Re:Writing an editor in less than 1000 lines of code, just f... by eatbitseveryday on Sunday July 10, 2016 @10:22PM (#12068469)
Middle finger goes up ;) (K), index down, stretch left to go left (H) or right to go right (L).
Re:Writing an editor in less than 1000 lines of code, just f... by dorfsmay on Sunday July 10, 2016 @03:31PM (#12066888)
I know k is up, because I constantly <ESC> k in bash, bit the point of using hjkl is exactly not to know which one is what. You set your finger on the keyboard in home position, now your muscle memory does the rest.
Re:Writing an editor in less than 1000 lines of code, just f... by coldtea on Sunday July 10, 2016 @04:31PM (#12067140)
>I know k is up, because I constantly <ESC> k in bash

What is ESC-k supposed to do in Bash?

Re:Writing an editor in less than 1000 lines of code, just f... by tbirdz on Sunday July 10, 2016 @05:10PM (#12067287)
The poster probably changed his bash to use vi editing mode with set -o vi. In this mode, <ESC>k would put the text of the last command entered back on the prompt.
Re:Writing an editor in less than 1000 lines of code, just f... by dorfsmay on Sunday July 10, 2016 @08:23PM (#12067985)
I do switch deadline to vi mode, since that's the editor I use the most.

I'm always surprised by people who are on the vi/vim side of vi/emacs debates but then use the defaults emacs mode in deadline!

Re:Writing an editor in less than 1000 lines of code, just f... by imron on Monday July 11, 2016 @12:29AM (#12068899)
The one under my middle finger on my right hand.

I don't even have to think, it's automatic. Likewise with the other directions.

Re:Writing an editor in less than 1000 lines of code, just f... by rzzzt on Sunday July 10, 2016 @06:00PM (#12067457)
'k' is up, because the author is typing quite a few of it in the screencast before going up. :)
Re:Writing an editor in less than 1000 lines of code, just f... by chongli on Sunday July 10, 2016 @03:27PM (#12066862)
k of course. Having said that, experienced vi/vim users rarely use jk to get around. Instead we use { } / f etc.
Re:Writing an editor in less than 1000 lines of code, just f... by bbcbasic on Sunday July 10, 2016 @06:41PM (#12067620)
I have no idea is a muscle memory thing :-)
Re:Writing an editor in less than 1000 lines of code, just f... by green7ea on Sunday July 10, 2016 @06:19PM (#12067531)
Not in insert mode, it will insert 'h', 'j', 'k' and 'l' ;-)
Re:Writing an editor in less than 1000 lines of code, just f... by dwaxe on Sunday July 10, 2016 @02:34PM (#12066609)
j and k behavior may vary depending on your config.
Re:Writing an editor in less than 1000 lines of code, just f... by edanm on Sunday July 10, 2016 @02:38PM (#12066634)
Everything can vary depending on your config, but unless they were explicitly remapped, j and k should pretty much do the same thing everywhere.

Have you seen somewhere where that isn't the case?

Re:Writing an editor in less than 1000 lines of code, just f... by zodiac on Sunday July 10, 2016 @04:15PM (#12067085)
> Have you seen somewhere where that isn't the case?

I use the dvorak keyboard layout and used to remap (among other things) j and k in vim, since they were not on the home row for me. I stopped doing that after a while though.