This is an story I found in ‘Learning vi and Vim Editors’ — which I started reading to ‘vim-maxx’:

Mary Ann Horton, who has been involved with Berkeley Unix since almost the begin‐
ning, tells the following story:
While the vi experience was much like Notepad, it was also a very powerful editor.
Students and faculty made heavy use of the power tools available, like the “global”
command that would make the same change on all lines matching some pattern, or
the ability to give commands likedelete 13 paragraphs” orcopy the text through the matching parenthesis.” But vi had a steep learning curve, and first-time users wanted
to use the arrow keys on their terminals to move around in the file, Notepad style.
Arrow keys didn’t work in vi, and for a very good reason. Users had a variety of
different brands of terminals, and all those terminals’ arrow keys sent different codes
when they were pressed.
Bill [Joy] didn’t have to worry about arrow keys. He had found a way to work from
home, getting a Lear-Siegler ADM-3A terminal in his apartment. The ADM-3A was
widely advertised as “the dumb terminal” because it didn’t have a lot of fancy features,
like arrow keys, allowing it to be sold for the then-low price of $995. Instead, LSI
painted arrows on the H, J, K, and L keys.4 Bill had set up vi commands to match: h
moved the cursor left, j down, k up, and l to the right. Every vi user had to learn h, j,
k, and l to move around the file.
What if you wanted to type a word with an “h” in it? vi, like ed, was a “moded” editor.
This meant you were either in “command mode,” where it treated keys you pressed as
commands, or “input mode,” where keystrokes were content to be added to the file.
A command like i forinsert” put you in input mode, and the Escape ( ESC ) key got
you back to command mode.
How to get arrow keys to work in vi? These special keys sent two or three character
sequences, usually beginning with Escape. We called them “escape sequences.” Escape,
however, was already an important vi command. It took you out of input mode, and
if you were already out of input mode, it beeped. One of the first things you learned
in vi was that, if you’d forgotten which mode you were in, you pressed the ESC key
until it beeped, and then you knew you were in command mode.
vi used a terminal capability database file called “termcap,” which told it which codes,
for your specific model terminal, to send to move the cursor, clear the screen, and the
like. It was easy enough to add the arrow key sequences to termcap.
If the computer received an Escape, was the user hitting the ESC key or an arrow
key? Should the editor exit input mode, or should it wait for more text to interpret
an arrow key? Once the editor tried to read more text, the program would hang until
something came in.
Fortunately, a new Unix feature allowed the editor to wait briefly to see if another
character came in. If that character might be part of a valid escape sequence, vi could
keep reading to see what other key the user had pressed. If no more characters came
in for that brief interval, the user must have pressed the ESC key. Problem solved!
Around the spring of 1979, I added code and termcap entries for vi to understand
arrow keys, Home, Page-Up, and other keys that some of the terminals had. I configured termcap as if the ADM-3a had arrow keys that sent h, j, k, and l; and
then I deleted the hardcoded h, j, k, and l commands. I thought I had it all fixed up.
Within a day, I had a line of angry CS grad students outside my office door. Peter
was at the head of the line. He wanted to know why I broke hjkl on his terminal. I
explained to him that his arrow keys worked now, and he didn’t have to use hjkl; he
could use the arrow keys instead.
Peter rolled his eyes. “You don’t understand,” he said. “We like using hjkl! We’re
touch typists. Our fingers are right over the hjkl keys. We don’t want to have to
move them way to the edge of the keyboard to use arrow keys. Give us back our hjkl
commands!” The line of students agreed.
They were right. I put back hjkl and left the arrow key functionality in too. And
I realized how important the key placements of vi commands were. Almost any
command you used often was a lowercase letter. I got really fast with vi, and to this
day I prefer vi to edit text files. I’ve trained several classes of IT professionals how to
get the most out of vi and Unix power tools.
  • pixxelkick@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    3 months ago

    What I want to know though is why the hell did he paint j as down and k as up.

    That has always seemed backwards to me.

    Left is back, and up is back. Right is forward, and so is down.

    We read left to right, and top to bottom.

    I constantly instinctually press K to go down, since it’s the right key, and down is “forward” in the document, but nope… it’s backwards and I go up instead.

    Several months of using nvim and I still fuck this up everytime. Whhhhyyyyy

    • Well I just use the arrow keys like a good IBM-PC cuck boy born in 1993. I mean the literal arrow keys. Keep one thing in mind, a keyboard in the late 70s, probably connected to:

      1- A dumb terminal, connected directly to a mini-computer such as VAX or my dear PDP-11, 2- A smart (or dumb) terminal, connected via 120mA current to a central mainframe,

      … may indeed HAVE or HAVE NOT arrow keys! Arrow keys are an IBM-PC thing, and even then, some clones omitted them. It was not until the IBM-derived PCs were standardized that we were sure there would be arrow keys on the keyboard.

      UNIX was ported over and over to several systems. It was originally on my dear PDP-11, but as people found it the great thing that it was (and still is!) they ported it over to their own systems. This led to its standardization through FIPS-POSIX. Later, Ken Thompson wrote ‘pcc’ or Portable C Compiler, and porting UNIX became easier. Before that, people used documents like Lion’s Commentary on the UNIX Source, which is what Stella’s Programmer’s Guide was to Atari 2600 is to UNIX.

      UNIX was originally designed for mini-computers, and time-sharing mainframes. It wasn’t until some Fingoloid whose name I keep forgetting, Linus Tech Tips or something, that a true UNIX for IBM PCs, or rather, 386, or rather, x86 PCs was born.

      So why did they just not use arrow keys? Because, I guess!

      • pixxelkick@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        3 months ago

        That wasn’t my question lol, I know why they used hjkl, I asked why they made j vs k backwards.

        J should have been up and K should have been down, but they have them flipped for no sensible reason.

          • pixxelkick@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            3 months ago

            I broke this down in my post.

            For a document up is back (the top is the start), and down is forward (we read top to bottom)

            Left is also back, and right is forward.

            We read left to right, and top to bottom.

            Thus, I also associate left with “back” and right with “forward”

            Thus j and k are backwards.

            J is left and thus “back”, so it should be up.

            K is right and thus forward and should be down.

            • wvstolzing@lemmy.ml
              link
              fedilink
              arrow-up
              1
              ·
              3 months ago

              That’s not a consideration in favor of grouping h/j as the ‘back keys’, and k/l as the ‘forward’ keys, though. It’s perfectly comfortable & intuitive to have the index finger on the key that goes forward.

      • pixxelkick@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        3 months ago

        I’m wondering if there was some other popular interface for some other device (elevators perhaps?) That had Down on left and Up on right.

        Since for an elevator, up is forward and down is backward…

        And I wonder if they copied from that order, not thinking about (or remotely expecting) the UX of how down on left would fuck people up for countless years to come.