Email or username:

Password:

Forgot your password?
Top-level
Julia Evans

some other things I think are interesting about the control codes:

* some of the "OS terminal driver stuff" is also sometimes handled by readline
* there are only 33 of them, so “Ctrl-1" is not a thing, Only Ctrl-A to Z plus seven more (@, [, \, ], ^, _, ?)
* You can't really use `Ctrl+M` as a keyboard shortcut because that's "Enter". Same for Ctrl-I.
* a lot of the "readline" ones will work even if you aren't using readline, many libraries mimic readline's functionality

22 comments
Athena L.M.

@b0rk several of the readline control codes are implemented as keyboard shortcuts in some common text editing widgets, particularly Ctrl+A/E

lucy 🌸

@b0rk ctrl+h is particularly weird for me because in GUI emacs that's the prefix for the help commands, but in the terminal it's backspace so I try and get help and accidentally delete my stuff

Bart Groeneveld

@b0rk That is also another hint for the 'j' in vim: go down one line, just like ctrl+j does in a terminal. Or is this just a coincident?

Gomijacogeo

@bartavi A bit of both plus a decision by an early terminal manufacturer. catonmat.net/why-vim-uses-hjkl

ASCII had already defined the codes and 8 (aka ^H or backspace) and 10 (aka ^J or linefeed) already had a kind of intrinsic left- and down-ness to them. 11 and 12 (^K and ^L, or vertical tab and formfeed) kind of implied motion, but had more meaning when terminals printed to paper rather than a screen.

The folks at LS decided since your fingers were already there, why not complete the arrow set.

@bartavi A bit of both plus a decision by an early terminal manufacturer. catonmat.net/why-vim-uses-hjkl

ASCII had already defined the codes and 8 (aka ^H or backspace) and 10 (aka ^J or linefeed) already had a kind of intrinsic left- and down-ness to them. 11 and 12 (^K and ^L, or vertical tab and formfeed) kind of implied motion, but had more meaning when terminals printed to paper rather than a screen.

_L4NyrlfL1I0

@bartavi @b0rk Likely coincidence. Have a look at "man ascii" and look at characters Decimal 1 to 26. Those are for the most part what you will get if it doesn't already do something special (like Ctrl+C).

For example, Ctrl+H is character 8, which is backspace (but only the backspace character). Ctrl+I is a tab, and Ctrl+J is a newline '\n'. (This means Ctrl+M is actually a carriage return '\r', but your os likely translates both into '\n' in the input that your terminal programs receive).

_L4NyrlfL1I0

@bartavi @b0rk I'm not actually completely sure what's going on with Ctrl+J and Ctrl+M, need to test that further.

Mark Eichin

@bartavi
Not a coincidence, just very specific history

Mark Dominus

@b0rk 0x7f is usually called "delete" or "DEL", to constrast it with 0x08 which is "backspace", and they are different and sometimes the terminal gets confused.

But your chart calls them both "backspace", which I think might tend to add to the amount of confusion in the universe.

Julia Evans

@mjd thanks that's a good point -- I'm very confused about what Ctrl-H does in practice -- to me it feels like 0x08 is just kind of some weird old cruft that has no real purpose but maybe that's not true

(if it does have a purpose I'd be interested to know what it is! I don't have a backspace key on my keyboard right now but my impression is that the backspace key is supposed to map to an ASCII DEL)

⛧ esoterik ⛧

@b0rk if you type "abcdef" at a prompt and then put your cursor between c and d (abc|def) then:

0x08 (backspace) usually produces ab|def

0x7f (delete) usually produces abc|ef

@mjd

Zack Weinberg

@b0rk @mjd I know that in the days of printing terminals and paper tape, the ASCII "backspace" and "delete" control codes had two clearly distinct functions.

Backspace meant literally back up the print head or tape punch one space. It *didn't* erase anything, and it was common to "overprint" two or more characters in the same space (a vestige of this survives today, some programs will emit a letter, ^H, and then _, and expect the letter to be underlined).

Delete, on the other hand, meant cross out the character at the *current* print head position. That's why it's all by itself at the high end of the ASCII range: its encoding is all-bits-1, which is all seven holes punched on a 7-bit paper tape, so if you back up your tape punch and punch DEL it completely destroys whatever used to be there.

I do not know how we got from there to how it is today.

@b0rk @mjd I know that in the days of printing terminals and paper tape, the ASCII "backspace" and "delete" control codes had two clearly distinct functions.

Backspace meant literally back up the print head or tape punch one space. It *didn't* erase anything, and it was common to "overprint" two or more characters in the same space (a vestige of this survives today, some programs will emit a letter, ^H, and then _, and expect the letter to be underlined).

Chris Siebenmann

@b0rk @mjd My memory is that there was a big schism in the physical terminal world about what the 'backspace' key generated. Many terminals had it generate Ctrl-H, but some used DEL; I believe DEC terminals such as the VT-100 were in the DEL camp, and they were very popular. This carried over to Unix workstations, with vendors doing different mappings (eg SGI made their 'backspace' key generate Ctrl-H in a default configuration; DEC used DEL of course).

Chris Siebenmann

@b0rk @mjd Today, X on Linux has a 'BackSpace' keysym and a 'Delete' keysym, generated by their respective keyboard keys, but I believe that all terminal emulators map both of them to DEL by default (xterm and gnome-terminal certainly do). Things like browsers tend to make the big BackSpace key delete characters to the left of the cursor (what you expect) and the 'Delete' key delete to the right, which can be a surprise.

Jef Poskanzer :batman:

@cks @b0rk @mjd With Unix caught in the middle of the schism, yeah. I had a small part in resolving things: at a Usenix 'ask the BSD team' session, I stood up and suggested that they deal with it by having two erase characters in the tty driver. And they said, Ok! Thus was born erase2.

Petru Ratiu

@cks @b0rk @mjd To this day my circle of IRC friends uses the mini-joke of ^H^H^H being poorly translated backspace presses even though we collectively forgot what chain of systems was needed to produce this specific "terminal mojibake".

Simon Tatham

@b0rk @mjd I see a lot of people have posted about history, but as I see it the _effects_ of the history are to create two current schools of thought.

1. the Backspace key (above Return) is 0x08, and the Del key (on the nav keypad) is 0x7F

2. Backspace is 0x7F, and Del is some sequence like ESC[3~ (similar to the rest of that keypad)

Emacs users like #2 because it frees up 0x08 to be ^H for help. But enough people like #1 that lots of software all needs a config option!

Stylus

@mjd @b0rk there's also the name "rubout" for code 127. The "all bits set" code was special on paper tape because you could change any other (incorrectly punched) code to it by re-punching. en.m.wikipedia.org/wiki/Delete

Chris Siebenmann

@b0rk Fun trivia on the Ctrl-1 and Ctrl-M and so on thing: non-terminal graphical programs with direct access to keypress information can bind them (of course). This is especially fun for programs that can operate either in the terminal or as stand-alone graphical applications, like GNU Emacs, because you can innocently create a binding for yourself that only works in GUI mode (which you might not notice for a while if you only rarely use the editor in a terminal).

Ben Zanin

@cks @b0rk like how avy-mode¹ recommends binding Ctrl-: in its default docs², with the consequence that it's unusable by folks who use terminal emacs (or a combination of GUI and terminal emacs panes connecting to a shared emacs daemon). Unless they're wizardly enough to feel comfortable reading all documentation about it when an interpretation filter in their brain!

¹: karthinks.com/software/avy-can

²: github.com/abo-abo/avy?tab=rea

maswan

@b0rk
I use ^M occasionally, in particular the combo of ^V^M to get a newline into a vim substitution expression.

Pope not Calle of Flaxborough

@b0rk fun fact about those “plus seven more” non-alphabetical Ctrl-codes, DEC VT220 terminals had alternate key bindings for them on Ctrl-2..8, in order.

Some emulators secretly support this as well, which is very convenient with keyboard layouts where some of those are awkward to type, or say… lacking an esc key, Ctrl-3 saves the day.

Go Up