Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

^H is the ASCII control character for backspace. It has nothing to do with vi, and everything to do with a terminal. It used to be common knowledge that when you press Backspace, sometimes ^H appears on your screen (if the program in question couldn't handle control characters natively). Naturally, in forum posts it started to have the meaning of "delete" for humorous purpose.

Its modern equivalent is HTML tag <del></del>, which also means "delete" due to the common knowledge of its meaning. One doesn't have to be a front-end developer to understand <del>, and one didn't have to be a vi user to understand ^H.



sort by: page size:

^H is the ASCII control character for "backspace".

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


I used ^H because that has become the standard way to indicate a "correction" for humorous purposes. As to why that became the standard, it does go back to the days before Delete keys started going where the Backspace key is supposed to be, requiring that the erase character be set to DEL to compensate. It has nothing to do with emacs.

The Backspace key had the same scan code as Control-H, so ^H is what you would see when you typed Backspace on a misconfigured TTY (instead of it deleting the previous character).

Control-W is what you use to delete the previous word (Edit: word, not character), so ^W is what you would have seen on TTYs/Editors that didn't support that command.


So, to be fair, C-h isn't some crazy invention of readline (and thereby a failure of what it was "advertising") that you got used to: it is the standard key code for backspace. Just like a horizontal tab is ASCII 9 and a carriage return is ASCII 13, ASCII 8--and I realize this might make less sense as this in some sense "undoes" a thing and maybe you would never expect it to be in a file--is backspace.

Meanwhile, all Control does is convert a normal (capital) character into a control character, which is the term for the ASCII characters below 32 (aka, the space character) by essentially subtracting 64 (which is almost but not quite equivalent to masking out a bit). Notably, @ is 64, so C-@ generates ASCII 0, which is why you see ^@ printed for NUL bytes in many editors (including vim). After @, you get A-Z and then [, \, ], ^, and _.

This is why, if you want to get Escape, you can type C-[, as ESC is 27 and [ is 91. And this is also how C-G becomes that annoying bell, because G is the 7th letter of the alphabet and BEL is 7, And so, C-M is equivalent to pressing Enter, C-J is equivalent to pressing Tab... and C-H is equivalent to pressing Backspace!! Now, there is also a DEL, for the Delete key, which is which is 127. As ASCII is designed for 7-bit, that is the same as -1, so you can type it using C-?, as ? is 63 ;P.

OK, so, one might should then wonder how the hell Emacs even works, if they remapped the character code for Backspace to do something silly like Help... right?! And the answer is kind of "it doesn't", which I find amazing! There is actually a FAQ entry for Emacs "Why does the Backspace key invoke help?" and a related section from its manual on "If DEL fails to delete". (It might even be the solution you came up with isn't the ideal one, so you might want to read these.)

https://www.gnu.org/software/emacs/manual/html_node/efaq/Bac...

https://www.gnu.org/software/emacs/manual/html_node/emacs/DE...


> C-h isn't some crazy invention of readline (...) that you got used to: it is the standard key code for backspace.

> C-H is equivalent to pressing Backspace!! Now, there is also a DEL, for the Delete key, which is which is 127

Not anymore on Linux terminals. People wanted to distinguish backspace and C-h, so in some time in 1990s there was great DEL-BS shift, where convention changed to use 127 for BS and some escape sequence for DEL (in direction from terminal to program, in the opposite direction the original convention is still used). That is why there are these sections in Emacs manual (and similar options on other tools) - to handle situations where terminal behavior and information about terminal are mismatched.


From http://en.wikipedia.org/wiki/Backspace:

Pressing the backspace key on a computer terminal would generate the ASCII code 08, BS or Backspace, which would delete the preceding character. That control code could also be accessed by pressing Control-H, as H is the eighth letter of the Latin alphabet. Terminals which did not have the backspace code mapped to the function of moving the cursor backwards and deleting the preceding character would display the symbols ^H (caret, H — see Caret notation) when the backspace key was pressed. This sequence is still used humorously for epanorthosis by computer literates, denoting the deletion of a pretended blunder, much like overstriking.

Example: My slave-dri^H^H^H^H^H^H^H^H^Hboss decided to stall the project.


The other answer to this is correct, but a little more detail in case you're interested:

^W is a control code. This specific one represents the keys ctrl+w, a keyboard command in Vi and Bash among other things. It deletes the previous word. You often see something similar with ^H as well, which is a single-character backspace. https://en.wikipedia.org/wiki/Backspace#^W_and_^U has some more information about these.

Some people use them more to make visual jokes in written text, more or less the same way you'd use strikethrough formatting in text.


It’s from the original borne / korn shell in Unix. Ctrl H was backspace, but the pc keyboards would send a different control character. you often had to map the backspace on the pc keyboard to make it work properly. Set -o or something like that.

Thanks. With a bit of deduction from your post, I just figured out why ^H is backspace.

ah, I was unfamiliar with the connotation between ctrl-H and backspace.

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:])


> It's also the only non-control ASCII character that can't be typed on an English keyboard

Don't count on it. There's a fairly long standing convention in some countries with some keyboard layouts that Control+Backspace is DEL. This is the case for Microsoft Windows' UK Extended layout, for example.

    [C:\]inkey Press Control+Backspace %%i & echo %@ascii[%i]
    Press Control+Backspace¦
    127
    
    [C:\]
This is also the case for the UK keyboard maps on FreeBSD/TrueOS. (For syscons/vt at least. X11 is a different ballgame, and the nosh user-space virtual terminal subsystem has the DEC VT programmable backspace key mechanism.)

> hitting the Delete key (the one up there above your Enter key)

Yup I meant the 'Backspace' key that looks like this: <---

Not the 'Delete' key that says 'Delete' and is clustered with End/Home/Insert etc.

Interestingly, on Windows machines, The backspace key sends ASCII 8, but can send ASCII 127 if you press control+backspace.


You can configure your terminal to send ^? instead of ^H (and use `stty erase '^?'` to configure your tty), but AFAIK there's no difference in the terminal between holding control while hitting backspace and not holding control (whether you have it set up to send the ^H or ^?), because of how keys map to ascii codes (see [0]).

Your terminal either sends ^H (0x08) or ^? (0x3f) (or really anything else you desire, if you can set up your terminal that way) when you hit backspace. control plus either of those keys would mean subtracting 0x40 from them, which is either negative or wraps around for both of them, so it's nonsensical.

Whereas, the GUI interprets the keyboard completely differently and allows you to express keys like "control + backspace". This is the main reason I prefer using gui versions of Emacs.

[0] https://en.wikipedia.org/wiki/Control_character#How_control_...


Excerpt from Hacker Writing Style (http://www.catb.org/~esr/jargon/html/writing-style.html):

There is also an accepted convention for ‘writing under erasure’; the text>

    Be nice to this fool^H^H^H^Hgentleman, he's visiting from corporate HQ.
reads roughly as “Be nice to this fool, er, gentleman...”, with irony emphasized. The digraph ^H is often used as a print representation for a backspace, and was actually very visible on old-style printing terminals. As the text was being composed the characters would be echoed and printed immediately, and when a correction was made the backspace keystrokes would be echoed with the string ‘^H’. Of course, the final composed text would have no trace of the backspace characters (or the original erroneous text).

Accidental writing under erasure occurs when using the Unix talk program to chat interactively to another user. On a PC-style keyboard most users instinctively press the backspace key to delete mistakes, but this may not achieve the desired effect, and merely displays a ^H symbol. The user typically presses backspace a few times before their brain realises the problem — especially likely if the user is a touch-typist — and since each character is transmitted as soon as it is typed, Freudian slips and other inadvertent admissions are (barring network delays) clearly visible for the other user to see.

Deliberate use of ^H for writing under erasure parallels (and may have been influenced by) the ironic use of ‘slashouts’ in science-fiction fanzines.


But with Ctrl, you have access to ^H, ^W, and ^U. It's 3 backspaces in one!

Yeah, crazy. It's Fn-Backspace to delete. Uncomfortable and no wonder almost no Mac user know about it. Maybe a reason for the gain in popularity of vim? It's X (upcase) to delete forward there.

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.


> There's no way to type a backspace without literally pressing backspace :)

ctrl-H usually works.

next

Legal | privacy