使用 $TERM='screen-256color'在 tmux 下,HOME 和 END 键不起作用。为什么?

发布于 2024-12-22 06:29:07 字数 839 浏览 2 评论 0 原文

我已将 tmux 设置为 $TERM 并正确设置为 screen-256color。这工作正常,并且颜色设置正确,但是它阻止我将 HOMEEND 键发送到终端,而是打印为 F\n< /code> 和 H\n

我应该补充一点,home 似乎可以在 irssi 中运行,但不能在 vim 中运行。 Home似乎发送(根据Ctrl+v ),^[OH

可能值得补充的是,我很清楚使用的能力>^$ 移动到行的开头和结尾,但是 $ 不会移动到末尾,而是移动到倒数第二个字符,我更喜欢使用 HOMEEND (就像我可以在其他 $TERM 设置下一样)。

谁能解释这是为什么,以及我该如何解决它?

作为部分修复,我将 vim 键绑定设置为将 按键映射到 OH 和 <代码>OF。这并不理想,但目前有效!有关详细信息,请参阅 https://github.com/jvc26/dotfiles/blob/master/.vimrc

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

没有伤那来痛 2024-12-29 06:29:07

上述映射方案不影响命令模式或视觉模式。在 tmux 或 vim 修复 bug 之前,以下是更理想的解决方案(放入您的 .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

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
兲鉂ぱ嘚淚 2024-12-29 06:29:07

作为修复,我将 vim 键绑定设置为将 按键映射到 OHOF

" 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

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
另类 2024-12-29 06:29:07

也可以按照 archlinux .inputrc 中设置键绑定>Home_and_End_keys_not_working.zshrczshwiki/zle/bindkeys。这个其他 stackoverflow 问题有一些额外的有用提示 home-end-keys-do -不在 tmux 中工作

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文