热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

zsh的Home/End键不使用putty。-Home/Endkeysinzshdon'tworkwithputty

ImrunningzshasthedefaultshellonaUbuntubox,andeverythingworksfineusinggnome-terminal

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.

我将zsh作为默认shell运行在一个Ubuntu框中,并且使用gnome-terminal(据我所知,它是xterm)可以很好地工作。当我通过ssh和putty(也同样模拟xterm)从windows系统中登录时,home/end键不再起作用。

I've been able to solve that adding these lines to my zshrc file...

我已经能够解决将这些线添加到我的zshrc文件中…

bindkey '\e[1~' beginning-of-line
bindkey '\e[4~' end-of-line

...but I'm still wondering what's wrong here. Any idea?

…但我还是想知道这里怎么了。任何想法?

6 个解决方案

#1


55  

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.

ZSH开发人员不认为ZSH应该定义Home、End、Del、……钥匙。

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):

Debian和Ubuntu通过定义普通用户在全局/etc/zsh/zshrc文件中期望的正常操作来解决这个问题。遵循相关代码(Debian和Ubuntu的代码是相同的):

if [[ "$TERM" != emacs ]]; then
[[ -z "$terminfo[kdch1]" ]] || bindkey -M emacs "$terminfo[kdch1]" delete-char
[[ -z "$terminfo[khome]" ]] || bindkey -M emacs "$terminfo[khome]" beginning-of-line
[[ -z "$terminfo[kend]" ]] || bindkey -M emacs "$terminfo[kend]" end-of-line
[[ -z "$terminfo[kich1]" ]] || bindkey -M emacs "$terminfo[kich1]" overwrite-mode
[[ -z "$terminfo[kdch1]" ]] || bindkey -M vicmd "$terminfo[kdch1]" vi-delete-char
[[ -z "$terminfo[khome]" ]] || bindkey -M vicmd "$terminfo[khome]" vi-beginning-of-line
[[ -z "$terminfo[kend]" ]] || bindkey -M vicmd "$terminfo[kend]" vi-end-of-line
[[ -z "$terminfo[kich1]" ]] || bindkey -M vicmd "$terminfo[kich1]" overwrite-mode

[[ -z "$terminfo[cuu1]" ]] || bindkey -M viins "$terminfo[cuu1]" vi-up-line-or-history
[[ -z "$terminfo[cuf1]" ]] || bindkey -M viins "$terminfo[cuf1]" vi-forward-char
[[ -z "$terminfo[kcuu1]" ]] || bindkey -M viins "$terminfo[kcuu1]" vi-up-line-or-history
[[ -z "$terminfo[kcud1]" ]] || bindkey -M viins "$terminfo[kcud1]" vi-down-line-or-history
[[ -z "$terminfo[kcuf1]" ]] || bindkey -M viins "$terminfo[kcuf1]" vi-forward-char
[[ -z "$terminfo[kcub1]" ]] || bindkey -M viins "$terminfo[kcub1]" vi-backward-char

# ncurses fogyatekos
[[ "$terminfo[kcuu1]" == "^[O"* ]] && bindkey -M viins "${terminfo[kcuu1]/O/[}" vi-up-line-or-history
[[ "$terminfo[kcud1]" == "^[O"* ]] && bindkey -M viins "${terminfo[kcud1]/O/[}" vi-down-line-or-history
[[ "$terminfo[kcuf1]" == "^[O"* ]] && bindkey -M viins "${terminfo[kcuf1]/O/[}" vi-forward-char
[[ "$terminfo[kcub1]" == "^[O"* ]] && bindkey -M viins "${terminfo[kcub1]/O/[}" vi-backward-char
[[ "$terminfo[khome]" == "^[O"* ]] && bindkey -M viins "${terminfo[khome]/O/[}" beginning-of-line
[[ "$terminfo[kend]" == "^[O"* ]] && bindkey -M viins "${terminfo[kend]/O/[}" end-of-line
[[ "$terminfo[khome]" == "^[O"* ]] && bindkey -M emacs "${terminfo[khome]/O/[}" beginning-of-line
[[ "$terminfo[kend]" == "^[O"* ]] && bindkey -M emacs "${terminfo[kend]/O/[}" end-of-line
fi

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).

所以,如果你连接到Debian或Ubuntu,你就不用做任何事情。所有事情都应该自动进行(如果不是,请参见下面)。

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/Ubuntu zshrc to your own .zshrc.

但是…如果您连接到另一个框(例如FreeBSD),则可能没有用户友好的默认zshrc。解决方案当然是将Debian/Ubuntu zshrc中的线条添加到你自己的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 an xterm. Or an xterm terminal isn't expected to send those or whatever... (Del key does work in xterm however, if you configure it in ZSH). Also notice that your Numpad-keys act funny in Vim for example with xterm terminal.

Putty将xterm作为终端类型发送给远程主机。但是在某个地方弄乱了,没有把正确的控制代码发送回家,结束,……这是xterm的期望。或者xterm终端不需要发送这些或其他…(但是,如果您在ZSH中配置它,那么Del键可以在xterm中工作)。还要注意,在Vim中,您的numpadkey在使用xterm终端时表现得很有趣。

The solution is to configure Putty to send another terminal type. I've tried xterm-color and linux. xterm-color fixed the Home/End problem, but the Numpad was still funny. Setting it to linux fixed both problems.

解决方案是配置Putty以发送另一个终端类型。我尝试过xterm-color和linux。xterm-color修复了Home/End问题,但是Numpad仍然很有趣。将其设置为linux解决了这两个问题。

You can set terminal type in Putty under Connection -> Data. Do not be tempted to set your terminal type in your .zshrc with export 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.

您可以在连接->数据下的Putty中设置终端类型。不要试图在您的.zshrc中设置您的终端类型=linux,这是错误的。终端类型应该由你的终端应用程序来指定,所以如果你从Mac的一个Mac盒连接到Mac SSH客户端,它可以设置自己的终端类型。

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.

注意,术语指定了终端类型,与连接的主机无关。我可以将终端类型设置为Putty中的linux,并连接到FreeBSD服务器,没有问题。

So, fix both these things and you should be fine :)

所以,把这两件事都搞定,你就会没事了:)

#2


13  

On the PuTTY configuration dialog, go to Connection -> Data and type linux into the Terminal-type string before connecting.

在PuTTY配置对话框中,连接->数据,并在连接之前将linux输入到终端类型的字符串中。

#3


5  

This is working for me

这是为我工作。

bindkey -v

bindkey '\eOH'  beginning-of-line
bindkey '\eOF'  end-of-line

#4


3  

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... :-)

这似乎是一件腻味的事。gnome终端发送代码^[哦和^[分别为Home和End,腻子发送^[[1 ~ ^[[4 ~。腻子有一个选项来改变Home /结束键从标准模式,rxvt模式,这似乎是个解决问题的关键,但不是结束键(现在发送^[噢)。我猜是时候在某个地方提交错误报告了……:-)

#5


2  

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.

应该在所有发行版中移植的合适的答案(不是所有版本的zsh,这里的ymmv)是使用zkbd的zkbd辅助工具。

Keyboard Definition
The large number of possible combinations of keyboards, workstations, terminals, emulators, and window systems makes it impossible for zsh to have built-in key bindings for every situation. The zkbd utility, found in Functions/Misc, can help you quickly create key bindings for your configuration.

键盘定义:键盘、工作站、终端、仿真器和窗口系统的大量可能组合,使得zsh不可能在每种情况下都有内置的键绑定。在函数/Misc中发现的zkbd实用程序可以帮助您快速为配置创建密钥绑定。

Run zkbd either as an autoloaded function, or as a shell script:

运行zkbd作为一个自动操作的函数,或者作为一个shell脚本:

zsh -f ~/zsh-4.3.17/Functions/Misc/zkbd

When you run zkbd, it first asks you to enter your terminal type; if the default it offers is correct, just press return. It then asks you to press a number of different keys to determine characteristics of your keyboard and terminal; zkbd warns you if it finds anything out of the ordinary, such as a Delete key that sends neither ^H nor ^?.

当您运行zkbd时,它首先要求您输入终端类型;如果它提供的默认值是正确的,只需按return键。然后它要求你按一些不同的键来决定你的键盘和终端的特性;zkbd警告你如果发现任何不寻常的事情,比如一个删除键发送不^ H ^ ?。

The keystrokes read by zkbd are recorded as a definition for an associative array named key, written to a file in the subdirectory .zkbd within either your HOME or ZDOTDIR directory. The name of the file is composed from the TERM, VENDOR and OSTYPE parameters, joined by hyphens.

zkbd读取的击键被记录为一个名为key的关联数组的定义,它被写入子目录中的一个文件中。zkbd在您的HOME或ZDOTDIR目录中。该文件的名称由术语、供应商和OSTYPE参数组成,由连字符连接。

You may read this file into your .zshrc or another startup file with the source' or.' commands, then reference the key parameter in bindkey commands, like this:

您可以将该文件读入您的.zshrc或其他启动文件。命令,然后引用bindkey命令中的关键参数,如下所示:

          source ${ZDOTDIR:-$HOME}/.zkbd/$TERM-$VENDOR-$OSTYPE
          [[ -n ${key[Left]} ]] && bindkey "${key[Left]}" backward-char
          [[ -n ${key[Right]} ]] && bindkey "${key[Right]}" forward-char
          # etc.

Note that in order for `autoload zkbd' to work, the zkdb file must be in one of the directories named in your fpath array (see zshparam(1)). This should already be the case if you have a standard zsh installation; if it is not, copy Functions/Misc/zkbd to an appropriate directory.

注意,为了让“autoload zkbd”工作,zkdb文件必须位于fpath数组中指定的目录中(见zshparam(1))。如果您有一个标准的zsh安装,那么应该已经是这样了;如果不是,将函数/Misc/zkbd复制到适当的目录。

see man -P "less -p 'keyboard definition'" zshcontrib, or search the meta-manpage zshall

见man -P“less -P”键盘定义“zshb,或搜索meta-manpage zshall。

#6


0  

These bindings simply don't appear to be part of the default bindings set in emacs mode.

这些绑定看起来并不是emacs模式中设置的默认绑定的一部分。

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 :-)

在运行“bindkey -e”后,在我的默认zsh安装上执行“where-is begining -of- of-line”显示它只绑定到a。也许你应该问问zsh的开发人员为什么:-)


推荐阅读
author-avatar
落雪念伯言
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有