Hacker News new | ask | show | jobs
by notRobot 2023 days ago
Off-topic, but why map a function to a multi-key combination when it already has a key dedicated to it?
6 comments

caret notation just maps all ASCII control characters to ^ + letter, many of which do not always have keys. "Backspace" is 0x08 = 8th letter is H = ^H

it's also not just used as an input, but also what a terminal that can't do or doesn't understand a backspace as "delete character, step to the left" prints instead.

Not just letters! "^X" indicates "X, but with the control-bit flipped", where the control-bit is the left-most of ASCII's 7 bits.

    1001000 ASCII 'H'
    1000000 "ctrl bit"
    0001000 ASCII backspace
But like I said, it's not just letters, if you use `cat -v` to show all non-printable characters in this notation, you'll also see things like "^@" for the 0x00 null byte and "^[" for the ESC. All of the terminal color-code control sequences start with ESC, so if you pipe colorized output to `cat -v`, you'll see a lot of "^[".
Huh I guess that explains why they chose [ as the second byte in the initiator for color control sequences: ESC [ = ^[ [
^H is the ASCII control character for "backspace".

https://en.wikipedia.org/wiki/Control_character

I would guess it's a side effect of having all ascii control chars mapped to key combos [1]

[1] https://en.wikipedia.org/wiki/ASCII#Control_code_chart

I don't remember what I was connecting to, but I've had telnet sessions that couldn't process backspace etc, so I had to use the ESC-<key> mappings.
Early keyboards maybe? Hjkl vs jkl;
I don't think that's the answer to the backspace=^h question, but HJKL is precisely an artifact of the keyboard that vi was first used on: https://en.wikipedia.org/wiki/File:KB_Terminal_ADM3A.svg / https://en.wikipedia.org/wiki/Vi#Creation - in addition to HJKL being labeled as the arrow keys on that keyboard, also note the far superior placement of escape and control where modern keyboards typically place tab and caps lock; this also made vi a lot more sensible.

(And of course that last bit is a whole topic unto itself; to this day, caps lock is the dumbest key on the whole keyboard to me - mostly useless, takes up prime real estate, and 100% worth remapping on every machine I control. But that's a rant for another day:])

Because the h-key is in the middle row of the keyboard, meaning relatively shorter keyboard distance needed to execute that common command, thereby saving typing time.