Add the following to your .tmux.conf
:
bind-key -n Home send Escape "OH"
bind-key -n End send Escape "OF"
And you're done!
Explanation
After attempting each one of these, and several others I saw while perusing other answers and documentation, this finally worked for me in every scenario I threw at it. I can't promise the same for you, because everyone's scenarios are different, but this is what I ended up with.
This was discovered after introducing the same trial/error and logic from a somewhat relevant article that is no longer available. The key is where the translation is occurring; in my case, this happens within my .tmux.conf
, rather than .bashrc
or .zshrc
(mainly because my home/end worked fine outside of tmux
)
Debugging
You can debug this issue by using cat -v
.
Run cat -v
, then press the Home and End keys. Exit using Ctrl+C.
$ cat -v
Here's what my output looked like within tmux using zsh
, zsh
, and bash
:
tmux
➜ ~ cat -v
^[[1~^[[4~^C
zsh
➜ ~ cat -v
^[[H^[[F
bash
bash-3.2$ cat -v
^[[H^[[F
Solutioning
Compare the above examples to what we're expecting to see, by pairing tput
with cat -v
:
$ tput khome | cat -v; echo
^[OH
$ tput kend | cat -v; echo
^[OF
Conclusion
Because this problem exists solely within tmux
, and not within the shells themselves, I opted to make the bind changes within the tmux configuration instead. By using bind-key
paired with send
, we can use the Escape
keyword paired with the sequence we want to achieve our translation. Thus:
bind-key -n NAME_OF_KEY send Escape SEQUENCE_GOES_HERE
This debugging and solutioning process can be applied to any other key translation issues. But, don't go too crazy. Some keys are mapped to certain escape sequences for a reason. Notice how bash
and zsh
received the ^[[H
sequence for Home instead of ^[OH
; it's probably not recommended we override this in our .zshrc
unless we're having major issues with this in zsh
.
ctrl-A/E/F/B/
alt-B/F...
(emacs bind) to move cursor