zsh 中的 Home/End 键不适用于 putty
我在 Ubuntu 机器上运行 zsh 作为默认 shell,并且使用 gnome-terminal (据我所知它模拟 xterm)一切正常。 当我通过 ssh 和 putty(也模拟 xterm)从 windows 盒子登录时,home/end 键突然不再起作用。
我已经能够解决将这些行添加到我的 zshrc 文件中的问题...
bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
...但我仍然想知道这里出了什么问题。 任何想法?
I'm running zsh as the default shell on a Ubuntu box, and everything works fine using gnome-terminal (which as far as I know emulates xterm). When I login from a windows box via ssh and putty (which also emulates xterm) suddendly the home/end keys no longer work.
I've been able to solve that adding these lines to my zshrc file...
bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line
...but I'm still wondering what's wrong here. Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
这对我有用。
将这些行添加到 ~/.zshrc
This worked for me.
Adding these lines to ~/.zshrc
这些绑定似乎不属于 emacs 模式中设置的默认绑定的一部分。
运行“bindkey -e”后在我的默认 zsh 安装上执行“where-is begin-of-line”显示它仅绑定到 ^a。 也许你应该问 zsh 开发人员为什么:-)
These bindings simply don't appear to be part of the default bindings set in emacs mode.
executing "where-is beginning-of-line" on my default zsh installation after running "bindkey -e" shows it is only bound to ^a. Perhaps you should ask the zsh developers why :-)
看来是个腻子的东西。 Gnome 终端分别发送
^[OH
和^[OF
表示 Home 和 End,而 putty 则发送^[[1~
和 <代码>^[[4~. putty 中有一个选项可以将 Home/End 键从 standard 模式更改为 rxvt 模式,这似乎可以修复 Home 键,但不能修复 End 键(现在发送^[Ow
)。 猜猜是时候在某个地方提交错误报告了......:-)It seems a putty thing. Gnome-terminal sends the codes
^[OH
and^[OF
for Home and End respectively, while putty sends^[[1~
and^[[4~
. There's an option in putty to change the Home/End keys from standard mode to rxvt mode, and that seems to fix the Home key, but not the End key (which now sends^[Ow
). Guess it's time to file a bug report somewhere... :-)在 PuTTY 配置对话框中,转到“连接”->“连接” 数据并在连接之前在终端类型字符串中输入 linux。
On the PuTTY configuration dialog, go to Connection -> Data and type linux into the Terminal-type string before connecting.
距离这个问题首次提出已经过去近 11 年了。 当时,一些发行版确实附带了 putty terminfo 条目,但它充其量只是平庸。 从那以后的几年里,情况有所改善,十多年来所必需的黑客攻击已不再需要。 PuTTY 仍然默认将
TERM
设置为xterm
以实现兼容性,但如果您要连接到现代的最新系统,您可能会幸运地覆盖此设置,并且将其设置为putty-256color
:putty-256color
的 terminfo 条目:toe -a | grep -F putty
putty-256color
。COLORTERM
真彩色
/etc/ssh/sshd_config
并将COLORTERM
添加到AcceptEnv
行。TERM
后运行exec zsh
。 zsh 在运行时不会对TERM
中的更改做出反应。TERM
实际上设置为您想要的内容:echo $TERM
screen
还是tmux
? 那又是一整罐蠕虫。 首先进行测试,以缩小问题发生的范围。 在 tmux 中,尝试设置TERM=tmux-256color
。 在屏幕中,尝试TERM=screen-256color
。It's now been nearly 11 years since this question was first posted. At the time, some distros did ship with a
putty
terminfo entry, but it was mediocre at best. In the years since, the situation has improved, and the hacks that were necessary for over a decade are no longer required. PuTTY still defaults to settingTERM
toxterm
for compatibility, but if you're connecting to modern, up-to-date systems, you'll likely have luck overriding this and setting it toputty-256color
:putty-256color
:toe -a | grep -F putty
putty-256color
.COLORTERM
truecolor
/etc/ssh/sshd_config
and addCOLORTERM
to theAcceptEnv
line.exec zsh
after changingTERM
. zsh won't react to changes inTERM
while it's running.TERM
is actually set to what you intended:echo $TERM
screen
ortmux
? That's another whole can of worms. Test without those first to narrow down where the issue is occurring. Within tmux, try settingTERM=tmux-256color
. Within screen, tryTERM=screen-256color
.这对我有用
This is working for me
应该在所有发行版(不一定是 zsh 的所有版本,这里是 ymmv)之间移植的正确答案是使用 zkbd 中的 zkbd 帮助程序实用程序。
请参阅
man -P "less -p 'keyboardDefinition'" zshcontrib
,或搜索元手册页zshall
the appropriate answer that should be portable across all distros (not necessarly all versions of zsh though, ymmv here) is to use the zkbd helper utility from zkbd.
see
man -P "less -p 'keyboard definition'" zshcontrib
, or search the meta-manpagezshall
我发现它是一个组合:
One
ZSH 开发人员认为 ZSH 不应该定义 Home、End、Del 的操作,...键。
Debian 和 Ubuntu 通过在全局
/etc/zsh/zshrc
文件中定义普通用户期望的正常操作来解决此问题。 遵循相关代码(在 Debian 和 Ubuntu 上是相同的):因此,如果您要连接到 Debian 或 Ubuntu 机器,则无需执行任何操作。 一切都应该自动工作(如果没有,请参见下文)。
但是...如果您连接到另一个机器(例如 FreeBSD),可能没有用户友好的默认值
zshrc
。 解决方案当然是将 Debian/Ubuntuzshrc
中的行添加到您自己的.zshrc
中。Two
Putty 将
xterm
作为终端类型发送到远程主机。 但在某个地方搞砸了,并且没有发送 Home、End 的正确控制代码,...这是人们期望从xterm
获得的。 或者xterm
终端预计不会发送这些内容或其他内容...(Del 键在
xterm
中确实有效,但是,如果您对其进行配置在 ZSH 中)。 另请注意,您的数字键盘在 Vim 中表现得很有趣,例如在xterm
终端中。解决方案是将 Putty 配置为发送另一种终端类型。 我尝试过 xterm-color 和 linux。
xterm-color
修复了 Home/End 问题,但数字键盘仍然很有趣。 将其设置为linux
解决了这两个问题。您可以在 Putty 中的“连接”->“连接”下设置终端类型。 数据。 不要试图在
.zshrc
中使用export TERM=linux
设置终端类型,这是错误的。 终端类型应由您的终端应用程序指定。 例如,如果您从 Mac 机与 Mac SSH 客户端进行连接,它可以设置自己的终端类型。请注意,TERM 指定您的终端类型,与您要连接的主机无关。 我可以在 Putty 中将终端类型设置为 linux 并毫无问题地连接到 FreeBSD 服务器。
所以,解决这两个问题就可以了:)
I found it's a combination:
One
The ZSH developers do not think that ZSH should define the actions of the Home, End, Del, ... keys.
Debian and Ubuntu fix this by defining the normal actions the average user would expect in the global
/etc/zsh/zshrc
file. Following the relevant code (it is the same on Debian and Ubuntu):So, if you are connecting to a Debian or Ubuntu box, you don't have to do anything. Everything should work automagically (if not, see below).
But... if you are connecting to another box (e.g. FreeBSD), there might be no user friendly default
zshrc
. The solution is of course to add the lines from the Debian/Ubuntuzshrc
to your own.zshrc
.Two
Putty sends
xterm
as terminal type to the remote host. But messes up somewhere and doesn't send the correct control codes for Home, End, ... that one would expect from anxterm
. Or anxterm
terminal isn't expected to send those or whatever... (Del key does work inxterm
however, if you configure it in ZSH). Also notice that your Numpad-keys act funny in Vim for example withxterm
terminal.The solution is to configure Putty to send another terminal type. I've tried
xterm-color
andlinux
.xterm-color
fixed the Home/End problem, but the Numpad was still funny. Setting it tolinux
fixed both problems.You can set terminal type in Putty under Connection -> Data. Do not be tempted to set your terminal type in your
.zshrc
withexport TERM=linux
, that is just wrong. The terminal type should be specified by your terminal app. So that if, for example, you connect from a Mac box with a Mac SSH client it can set it's own terminal type.Notice that TERM specifies your terminal type and has nothing to do with the host you are connecting to. I can set my terminal type to
linux
in Putty and connect to FreeBSD servers without problems.So, fix both these things and you should be fine :)