Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With $TERM='screen-256color' under tmux, HOME and END keys don't work. Why?

Tags:

I have tmux set up with $TERM being set to screen-256color correctly. This works fine, and colours are set correctly, however it prevents me from sending HOME and END keys to the terminal, which are instead printed as F\n and H\n.

I should add that home appears to work in irssi, but not vim. Home seems to send (According to Ctrl+v <HOME>), ^[OH

It may be worth adding that I am well aware of the ability to use ^ and $ to move to the start and end of the lines, however $ does not go to the end, rather the penultimate character, and I prefer to use HOME and END (as I can under other $TERM settings).

Can anyone explain why this is, and how I can fix it?

As a part-way fix, I set the vim keybindings to map a <Home> and <End> keypress to <Esc>OH and <Esc>OF. This isn't ideal, but works for the moment! See https://github.com/jvc26/dotfiles/blob/master/.vimrc for details.

Thanks!

like image 856
jvc26 Avatar asked Dec 22 '11 12:12

jvc26


2 Answers

The above mapping solution doesn't affect the command mode or visual mode. The following is a more ideal solution until either tmux or vim fixes the bug (put in your .vimrc):

"""""""""""""" " tmux fixes " """""""""""""" " Handle tmux $TERM quirks in vim if $TERM =~ '^screen-256color'     map <Esc>OH <Home>     map! <Esc>OH <Home>     map <Esc>OF <End>     map! <Esc>OF <End> endif 
like image 119
Flowchartsman Avatar answered Sep 18 '22 08:09

Flowchartsman


As a fix, I set the vim keybindings to map a <Home> and <End> keypress to <Esc>OH and <Esc>OF.

" Handle TERM quirks in vim if $TERM =~ '^screen-256color'     set t_Co=256     nmap <Esc>OH <Home>     imap <Esc>OH <Home>     nmap <Esc>OF <End>     imap <Esc>OF <End> endif 
like image 44
jvc26 Avatar answered Sep 18 '22 08:09

jvc26