Search code examples
tmux

Backspace not working in tmux command prompt


I'm having trouble with my Backspace key on the tmux command prompt. The backspace deletes previous characters (as expected) within tmux but not on the tmux command prompt. For example, <PREFIX>:lists<DEL> will not delete the 's' character. Using C-h instead of the Delete key does delete the 's' character in this situation. C-? does NOT delete the 's' character. Some debugging I've done within the tmux window:

$TERM=screen-256color
infocmp reports kbs=\177                  (good)
appres XTerm | grep backarrowKeyIsErase   reports as true (good)
appres XTerm | grep ptyInitialErase       reports as true (good)
stty -a | grep erase                      reports as "^H" (bad, I think I want ^?)

I've also tried binding the Backspace key in the .tmux.conf as shown below to both C-h and C-?, neither work. :list-keys within tmux confirms that the mapping is occurring.

bind-key -n BSpace send-keys C-?

I've done a stty erase ^? as well, both before and after invoking tmux and that does not affect the behavior. Finally, I've removed my .tmux.conf entirely and still get the same behavior.

Does the command line use a different set of key bindings that would affect BSpace functionality?


Solution

  • The problem was because there was a mismatch between my $TERM settings, my .Xdefaults, the keybindings for the terminal (I use konsole) and whatever tmux was sending. My specific fix required getting Backspace set to ^? everywhere and NOT ^h. Additionally, tmux's $TERM is best set to screen-256colors or tmux-256colors so you need to ensure that those terminal modes can see the right key mappings.

    In my .Xdefaults, note that this is for all VT100 and not just XTerm*VT100 because I want screen, tmux, and konsole to see these entries:

    *VT100.Translations: #override \n\
       <Key>BackSpace:       string(0x7F) \n\
       <Key>Delete:          string("\033[3~")
    
    *ttyModes: erase ^?
    

    I also had to fix my bindkeys in my ~/.cshrc:

    bindkey -a "\e[3~" delete-char
    stty erase ^?
    

    ... and also add a similar entry to an ~/.inputrc file (which konsole reads):

    "\e[3~": delete-char