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

泪湿孤枕 提交于 2019-12-02 20:29:53

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

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
here

It is also possible to set the keybindings in the .inputrc as explained on archlinux Home_and_End_keys_not_working or .zshrc as on zshwiki/zle/bindkeys. This other stackoverflow question has some additional useful tips home-end-keys-do-not-work-in-tmux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!