3

I'm having a strange problem:

When sshing into a particular host (from OSX to RHEL5), vim seems to forget how to backspace, but only in a tmux session, ie:

  ssh foo@bar.com
  vim test

Backspace works fine above.

This doesn't however:

  ssh foo@bar.com
  tmux
  vim test

Hitting backspace in insert mode produces ^? What could the problem be?

3
  • 1
    Does pressing Ctrl-H work? If so, check out this setting (focused) in Terminal.
    – Daniel Beck
    Apr 10, 2012 at 17:13
  • Unfortunately im using iterm2 :) Apr 10, 2012 at 17:29
  • Ctrl+H doesn't work for me =/ still gives same ^?
    – holms
    Aug 1, 2013 at 20:54

6 Answers 6

5

You might need to change your Terminal to send ^h when you type Backspace.

In Terminal's preferences, the setting is part of the profile, so you can set up a dedicated profile for your SSH connection to that RHEL5 system.

1
  • and how to change terminal in TMUX? i'm cygwin now and actually in cygwin this works fine, ssh'ing to rhel6.4 vim gives this problem, fixed term in vimrc, problem fixed, but in tmux it's still gives me the same problem
    – holms
    Aug 1, 2013 at 20:55
2

You can map the backspace key to what you need, like Kevin said. It looks like you need to map it to ^? (rather than ^H)

To do that, use the following command:

stty erase "^?"

This can be added to your startup scripts (.login or .tcshrc or .bashrc, or other files, depending on which shell you use).

0

I find giving this command

stty erase Ctrl-V BACKSPACE

works for me. However, I need to do this on every pane.

0

To fix backspace on Apple M1 Pro OSX 12.4 I had to do this

$(brew --prefix)/opt/ncurses/bin/infocmp tmux-256color > ~/tmux-256color.info
tic -xe tmux-256color ~/tmux-256color.info

Issues:

https://github.com/tmux/tmux/issues/1257#issuecomment-581378716

https://gist.github.com/bbqtd/a4ac060d6f6b9ea6fe3aabe735aa9d95

0

I made a workaround

  1. Make an alias in .alias

    alias emacs(or vi)='stty erase "^H"
    
    emacs'  
    
  2. Make a shell script

    # filename tmuxsh
    
    stty ek
    cmd=$(which tmux)      # tmux path
    session=$1
    if [ $# = 0 ]; then
       $cmd ls
       exit 0
    fi
    $cmd has -t $session 2> /dev/null
    if [ $? != 0 ]; then
         $cmd new -s $session
         exit 0
    fi
    $cmd att -t $session
    exit 0
    

Of course, you could make an alias too, alias tm=tmuxsh. then you could use emacs/vi both in tmux or out of tmux well.

Why make an emacs alias in step 1? Because if just use step 2, after quit tmux to normal shell, the emacs/vi will encounter the issue too.

It works well for me.

0
0

If you are using xshell like me,try to change Backspace from [Backspace(Ctrl+H)] to [ASCII 127(Ctrl+?)]. In my case, backspace works again in both bash\zsh\tmux+zsh. This problem has nothing to do with $TERM variable.

https://i.stack.imgur.com/M6y82.png

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.