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

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...



sort by: page size:

> 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.


^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.


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.


After getting very used to C-w (delete back work) and C-h (delete character backward) on readline, it really bugged me that these aren't default on emacs, even though readline is often advertised as giving emacs muscle memory.

I ended up globally remapping C-w and moving the help prefix, C-h to C-x h and making C-h backspace, because i was pressing it incorrectly that often.


> 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.)

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.

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.

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

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


Huh? Backspace works the same for me in Bash C-r as it does in Emacs C-r.

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_...


Haha. I'm an avid vim user and I don't get backspace. The normal key to move back by character is in the home-row. Why would I use backspace instead? Am I missing something?

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.


I wasn't quite aware of this because there are slight inconsistencies in some programs and between OSs.

e.g. in powershell on Windows, Ctrl+Backspace deletes the word part, but in cmd shell, Ctrl+Backspace deletes until whitespace. The keybindings to delete word also vary on Windows vs MacOS (Alt+Backspace deletes a word on mac, but deletes the whole line on Windows. Windows uses Ctrl+Backspace for that).

I was also confused since by-default Emacs doesn't treat `_` as a word character.


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

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.


CTRL-h doesn't behave the same as backspace on OS-X. This makes it hard to use for me. Cool idea though.

I don’t understand your backspace problem. In all of the following cases, Vim 7.3 and Emacs 24 with Evil act the same:

In Command-line mode (by typing `:`), when there is text after ‘:’ and before the cursor, typing Backspace deletes one character behind the cursor. In Command-line mode, if there is no text left but ‘:’, it exits Command-line mode, changing to Normal mode. Emacs displays Quit in this case, while Vim just exits silently. If I press Backspace in Normal mode while the cursor in the middle of a line, the cursor moves back one character as if you pressed `h`.

My full Evil config is here: https://github.com/roryokane/emacs.d/blob/master/init.el#L12.... But I don’t see anything in it that would change the behavior of Backspace.

I did just notice an inconsistency with Backspace, but it doesn’t sound like what you’re talking about: if you press Backspace in Normal mode while the cursor is at the leftmost column, the cursor wraps to the previous line in Vim, but stays in the same place in Emacs. The cause of that behavior in Vim is the 'whichwrap' option’s value containing “b”. Evil has a rough equivalent to that option in evil-cross-lines (a boolean), but I don’t know if it has an equivalent that lets you selectively enable wrapping only for Backspace and Space. https://bitbucket.org/lyro/evil/issue/247/evil-invert-char-s... implies that there was no exact equivalent as of Febraury 2013.


[1]

> In some unusual cases, Emacs gets the wrong information from the system, and <Backspace> ends up deleting forwards instead of backwards.

[2]

That's not the case with the GUI version because it works like any other application (File->Quit or the [x] button). In terminal it's a bit different but it's not like vim is any easier here.

next

Legal | privacy