News for hackers. Stuff that matters.
Re:Writing an editor in less than 1000 lines of code, just f... by petercooper on Sunday July 10, 2016 @08:45AM (#12065432)
And yet I read, on Hacker News, a number of people writing how they were often saved by the availability of nano on random systems

All the time, but I even use nano all the time on OS X for full on programming, mostly for quick edits or starting things off before I can be bothered opening a full project in Sublime. (Sure, I can 'get around' in vi, but I just don't seem to have the brain for it and nano is 90% fine. I grew up on GWBASIC so anything is an improvement ;-))

That aside, this feels like it could be a kinda cool command line level equivalent of ToDoMVC. Port this simple editor into Go, Rust, and a few similar languages - see what the differences are, etc.

Re:Writing an editor in less than 1000 lines of code, just f... by elsurudo on Sunday July 10, 2016 @02:04PM (#12066479)
Nice thing about Nano is that they arrow keys always seem to do what they are supposed to, no matter the system, shell, TTY, etc. Vi seems to have issues sometimes, and needs extra config
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.

Re:Writing an editor in less than 1000 lines of code, just f... by dozzie on Sunday July 10, 2016 @02:14PM (#12066520)
I don't know about vi (I think it's still rare on Linux systems), but Vim typically does what is expected from it.
Re:Writing an editor in less than 1000 lines of code, just f... by happyslobro on Sunday July 10, 2016 @03:24PM (#12066849)
If you ever happen to bork your kernel badly enough to prevent it from booting, you'll find a classic VI pretty quickly, and probably be grateful for it.
Re:Writing an editor in less than 1000 lines of code, just f... by dozzie on Sunday July 10, 2016 @03:50PM (#12066985)
Well, not really. My system doesn't have vi installed. Vim, of course, any time of the day. Stripped Vim (vim-tiny, as Debian calls it), sure, just after installation. But vi -- no, I don't have it installed.

For quite a long time Linux didn't have vi even ported. There were several clones, like Elvis and nvi (and Vim, of course). Few years ago I learned that somebody took the effort and actually ported traditional vi to Linux. I doubt mainstream distributions cared to include it, though. Why should they? They already have plethora of clones packaged, and those clones typically do much more than traditional vi.

The lesson from this tale is this: don't call vi what is merely a vi clone. vi is a name of a quite concrete project.

And as for kernel unable to boot: if it can't boot, then how the heck am I supposed to run anything under this kernel? Unless you meant kernel can't run OS from local disk. I know Linux well enough to manage to run my things. You would be surprised how much could you hack through if you knew how ELF binaries work.

Re:Writing an editor in less than 1000 lines of code, just f... by traviscj on Sunday July 10, 2016 @11:41PM (#12068742)
You are being needlessly pedantic. The point is that typing "vi" into a terminal runs some application that implements a "vi-ish" interface. Whether it is ported vi or vim or vim-tiny has some effect on how nice that interface is to work with, but I would argue that most vim users would be able to get their configuration fixed or whatever
Re:Writing an editor in less than 1000 lines of code, just f... by dozzie on Monday July 11, 2016 @04:43AM (#12069709)
> You are being needlessly pedantic.

I assure you I am not pedantic needlessly. The claim was "vi has some issues with arrow keys". Now tell me: which vi clone was elsurudo talking about? Because those are different projects. And Vim doesn't have a smallest issue with arrow keys (unless with "compatible" option set, I think, but I didn't use it for years and I may remember wrong).

Re:Writing an editor in less than 1000 lines of code, just f... by macintux on Monday July 11, 2016 @10:30AM (#12071265)
As a cranky old man, I'd argue all of them that support arrow keys have issues. Arrow keys are an abomination.
Re:Writing an editor in less than 1000 lines of code, just f... by alien3d on Sunday July 10, 2016 @10:16PM (#12068447)
I also use nano for my alternative notepad++ in windows. If normal ide i only use vscode in osx.