kakoune: Backspace key does not register under Xterm

Question

I’ve been postponing this issue for quite a while. It only happens under xterm.

At first I thought this annoying problem could have been caused by the initialization file, then I invoked kak -n but the problem persisted.

Backspace seems to work under kitty, or under kde’s konsole, or even under xfce4-terminal emulators.

It also works [backspace key] with the combination of either vim, neovim under xterm, or even emacs -nw

Modifying xorg configuration file for the keyboard layout and its options made no difference either.

KeyPress event, serial 37, synthetic NO, window 0x5000001,
    root 0x118, subw 0x0, time 385042, (110,-245), root:(661,91),
    state 0x0, keycode 22 (keysym 0xff08, BackSpace), same_screen YES,
    XLookupString gives 1 bytes: (08) "
    XmbLookupString gives 1 bytes: (08) "
    XFilterEvent returns: False

Heck. Changing even the physical board made also no difference.

It does not happen with the combination of kak any other terminal emulators, but with the same token, the other editors do not have the issue either registering the backspace key under xterm.

This is a good one. (Sarcastically speaking)

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 16 (14 by maintainers)

Most upvoted comments

I didn’t read the whole thread, but backspace in Kakoune stopped working for me in xterm after upgrading ncurses (6.3-2 -> 6.3-3) on Arch Linux. Downgrading ncurses fixes the problem.

The change in ncurses 6.3-3:

FS#74379 - [ncurses] Missing “configure” option --with-xterm-kbs=del

upgpkg: ncurses 6.3-3: Rebuild to add missing configure option

Recent versions of Kakoune do not depend on ncurses anymore.

I wrote up a bit about the history of Backspace handling in #3863. In brief:

  • On a VT100, the key above Enter with the left-pointing arrow sends ^H (byte 0x08).
  • On a VT200, that key sends ^? (byte 0x7F), but can be switched into a compatibility mode that sends 0x08, by default or at runtime
  • As a result, just about every tool has its own config option to determine what key should be interpreted as backspace
    • Linux has the ability to load custom keymaps for the console keyboard
    • All POSIX kernels can configure an individual terminal with stty erase
    • telnetis designed to support different backspace conventions on the host versus the client
    • the terminfo database has the kbs capability to define what the backspace key sends
    • Vim has the special t_kb and t_kD options, as well as the special :fixdel command to sort them out
    • Terminal emulators typically emulate the VT200 terminal’s runtime compatibility mode switch, as well as having their own GUI/config
    • xterm in particular seems to have at least four config options that affect its backspace behaviour, including the ptyInitialErase, ttyModes, backarrowKey, and backarrowKeyIsErase, plus with potentially consulting terminfo and the VT200 runtime compatibility switch

In short, there’s a lot of places that can be misconfigured, and a lot of apps (including shells) always treat both ^H and ^? as “backspace” just in case, so if things are misconfigured they can still work in some apps but not others.

Kakoune (since #3863) checks the stty erase value at startup, and whatever the kernel thinks the backspace key is, that’s what it treats as backspace.

…most likely after typing cat and hitting the backspace key, it will return ^? , correct?

Nope. If you run cat and hit the backspace key, it should not print anything, it should backspace over previous characters you’ve typed. If something appears, that means the kernel’s idea of backspace is different from the terminal’s. You can either reconfigure the kernel (with stty erase) or reconfigure the terminal, but once they agree, Kakoune should work.

Some questions:

  • what does stty -a | grep -o ' erase[^;]*' print inside xterm?
  • if you Ctrl-left-click on Xterm to bring up the “Main Options” menu, is there a tick next to the “Backarrow Key (BS/DEL)” menu item?
  • If you run cat inside xterm and press the backspace key, does it print anything?

As a concrete example, Debian policy is that the Backspace key should always produce ^?, not <c-h>, and every terminal emulator packaged in Debian behaves that way, by patching the source code if necessary. Other distros may have different policies, third-party packages may have different policies, and of course defaults can be changed (for example, to interoperate with systems with the opposite default).