Another what the heck moment in Fedora 43. In Gnome-terminal (only, not xterm), hitting 'Delete' in vim insert mode no longer deletes characters to the left of the cursor, only characters to the right. Delete is generating ^? in both gnome-terminal and xterm, and Delete works to delete characters in vim in g-t on the ':' command prompt.

Whatever vim / gnome-terminal combined stupidity this is, I want it gone. Now.

Well I have an answer to my vim and gnome-terminal thing and the answer is 'set noxtermcodes'. The other answer is that both gnome-terminal and vim have what I think are bugs that collude to allow this situation to happen. You can argue about exactly whose fault this was, but that's not really productive.

Well I guess there is a workaround in gnome-terminal by changing what it generates for 'Delete' (the key) to 'escape sequence'. What a mess.

I thought I could write a nice simple techblog entry about my gnome-terminal issue in vim and now I am opening up https://www.tuhs.org/ to look at 4.2 BSD manual pages.
The Unix Heritage Society

The Unix Heritage Society

@cks

Let me guess: historical termcap. (-:

Might be Joy+Horton #vi, but my first guess is #termcap.

The way that termcap, and even terminfo, handle switchable stuff like this is truly terrible, because it simply does not fit their model. They're poor on input sequences anyway.

#FreeBSD still uses termcap(5), pretty much the only operating system left that does, and its manual page discusses how one might want to be compatible with AT&T #Unix S5R2 in the future.

https://man.freebsd.org/cgi/man.cgi?query=termcap&sektion=5

termcap(5)

@JdeBP It was indeed historical termcap. I was curious if I could nail down where 'kd' for 'delete key sends this' was introduced, and it turns out to be 4.3 BSD (it doesn't seem to have been in 4.2). I don't know where the terminfo equivalent (kdch1) was introduced, but it may have been there more or less from the start of terminfo.
@cks
Is this the new terminal? I've tried it a bit and haven't yet seen this behavior.
@jannem It appears that the gnome-terminal default is for 'Delete' to send an escape sequence, but at some point my gnome-terminal settings shifted to Delete sending ASCII DEL, like Backspace.

@cks shouldn’t backspace send ^H and delete send ^?

what does stty say about the keys / characters?

@drscriptt One of the charming things about this issue is that stty is relatively irrelevant because vim plucks the key settings out of your terminal emulator. (Well, there is no stty for forward-delete, so one can't entirely blame vim.)

Modern standard X and Wayland behavior is that the physical BackSpace key generates ASCII DEL and the Delete key generates something else, typically an escape sequence rather than Ctrl-H.

@drscriptt @cks

The terminal line discipline has very little to do with it, as full-screen programs like VIM put the line discipline into non-canonical mode, where there are no special characters.

Where this issue lies, and has done since the 1980s, is emulating a DEC VT.

On an actual DEC VT the Backspace key is programmatically switchable between DEL and BS. #XTerm extended this years ago and makes the two Delete keys switchable between DEL and DECFNK 3.

#DECVTs #TerminalEmulators

@JdeBP @drscriptt TIL that the physical key was switchable instead of always generating DEL, which is what I'd absorbed.

(Switchable was useful because on other physical terminals the Backspace key generated ^H, so you might have software and setups that assumed that, then you got some DEC VTs and ...)

@cks @drscriptt

By the way: It's DEC Private Mode 67 (a.k.a. DECBKM) for controlling Backspace, and DEC Private Mode 1037 for Delete.

Not every terminal emulator understands these. But they're understood by things as wide ranging as hterm and mintty.

I copied these from #DECVTs and XTerm in my terminal emulator, and my #setterm has options for generating both DECSM/DECRM mode switches.

http://jdebp.info/Softwares/nosh/guide/commands/setterm.xml

#nosh #TerminalEmulators