如何修复 Vim 中的 Home 和 End?
我在 gnome-terminal (2.26.0) 中使用 vim:虽然我 95% 的时间使用“$”导航到 EOL,使用“0”导航到相反的位置,但时不时地我会点击“Home”或“结尾”。
当我使用 Home 时,当前行中的文本会向下移动,使当前行处于插入模式,并且字母 H 出现在行的开头。
当我按 End 时,情况是一样的,但用的是 F 而不是 H。
为什么会发生这种情况?我该如何修复它? (修复意味着按下这些键时具有标准功能)。
I'm using vim in gnome-terminal (2.26.0): although I use 95% of the time "$" to navigate to the EOL and "0" for the opposite, every now and then I hit "Home" or "End".
When I use Home, the text I have in the current line is moved on line down, leaving me in insert mode in the current line and the letter H appears at the beginning of the line.
When I hit End, it's the same but with an F instead of H.
Why does it happen? How can I fix it? (fixing would mean to have the standard functionality when hitting these keys).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生这种情况是因为在终端中按 home 和 end 键会向 vim 发送一个包含多个字符的转义序列,而 vim 无法正确地将这些转义序列与您按下的键关联起来。
要解决此问题,您需要调整术语设置。 Gnome-terminal 与 xterm 兼容,因此您可以尝试将其添加到 您的 .vimrc 中:
术语设置源自 TERM 环境变量,所以您可能想首先调查一下为什么它没有正确设置。
This happens because pressing the home and end keys in a terminal sends an escape sequence consisting of several characters to vim, and vim isn't correctly associating these escape sequences back with the keys you pressed.
To fix this you need to adjust the term setting. Gnome-terminal is xterm compatible, so you could try adding this to your .vimrc:
The term setting is derived from the TERM environment variable, so you might want to investigate why it isn't set correctly in the first place.