I'm currently using tmux with xterm-256color $TERM variable. When in bash under tmux, pressing home/end would insert tilde characters (~). Outside of tmux the home/end keys work fine.
Using cat and tput, I could see that there was a mismatch between the generated and expected sequences:
$ cat -v # pressing home, then end ^[[1~^[[4~ $ tput khome | cat -v; echo ^[OH $ tput kend | cat -v; echo ^[OF
To fix this, I decided to add the following to my .bashrc:
if [[ -n "$TMUX" ]]; then bind '"\e[1~":"\eOH"' bind '"\e[4~":"\eOF"' fi
That fixed the problem for bash, however in other readline programs, such as within a REPL such as ipython, it still inserts a tilde for home/end.
Why exactly is this a problem in the first place? Why is the generated sequence different when I'm inside tmux vs outside it? How can fix this so that it's not an issue in any programs?
A frequent problem in command line programs is that keys like Home and End do not work as expected. This is usually because the terminal emulator sends multi-character escape codes when such keys are pressed, which the running program (such as your shell) does not know how to interpret correctly.
End moves you to the last character in Word, Wordpad, or Notepad, or any other application that allows its use. The same is true of the Home key. It moves you to the beginning of the document or data set in any program that allows it or uses it.
It appears the main problem is with using xterm-256color for $TERM. I switched $TERM to screen-256color and the problem went away.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With