Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Home/End keys do not work in tmux

Tags:

linux

bash

tmux

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?

like image 801
Ben Davis Avatar asked Sep 03 '13 19:09

Ben Davis


People also ask

Why are my home and end keys not working?

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.

What are Home and End keys?

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.


1 Answers

It appears the main problem is with using xterm-256color for $TERM. I switched $TERM to screen-256color and the problem went away.

like image 86
Ben Davis Avatar answered Sep 19 '22 07:09

Ben Davis