!在zsh中调用搜索的字符

时间:2013-05-27 23:38:40

标签: zsh

我喜欢ZSH中有一个非常好的功能。当你输入!字符后跟一个单词+ TAB键,它使shell拉出最后一个命令,后面加上单词!并扩大它; e.g:

% !ssh

然后,预期的行为是您可以使用向上和向下箭头键在历史记录中循环,其范围仅限于以 ssh 开头的命令。现在,我在Mac OS X中使用它,但由于某种原因,我没有在我的Linux机器上得到它。在我的linux安装中,我的bindkeys看起来像这样:

 user@host ⮀ ~ ⮀ bindkey | fgrep history
"^N" down-line-or-history
"^O" accept-line-and-down-history
"^P" up-line-or-history
"^R" history-incremental-search-backward
"^S" history-incremental-search-forward
"^X^N" infer-next-history
"^Xr" history-incremental-search-backward
"^Xs" history-incremental-search-forward
"^[ " expand-history
"^[!" expand-history
"^[," _history-complete-newer
"^[/" _history-complete-older
"^[<" beginning-of-buffer-or-history
"^[>" end-of-buffer-or-history
"^[N" history-search-forward
"^[OA" up-line-or-history
"^[OB" down-line-or-history
"^[P" history-search-backward
"^[[5~" up-line-or-history
"^[[6~" down-line-or-history
"^[n" history-search-forward
"^[p" history-search-backward

为了获得预期的行为,我必须改变什么是bindkey?我已经改变了一些,但结果并不理想。如果有人能帮助我,我会很高兴的。我安装的zsh版本是5.0.2。

于5月30日星期四10:27:49 CEST 2013编辑:

@Francisco它有效。我不知道所需的选项是上线或搜索和下线或搜索。所以我做了如下:

1)我检查了哪些键已分配:

⮀ ~/.dotfiles ⮀ ⭠ ihacku ⮀ bindkey | fgrep search 
"^R" history-incremental-search-backward
"^S" history-incremental-search-forward
"^Xr" history-incremental-search-backward
"^Xs" history-incremental-search-forward
"^[N" history-search-forward
"^[OA" up-line-or-search
"^[OB" down-line-or-search
"^[P" history-search-backward
"^[[A" up-line-or-search
"^[[B" down-line-or-search
"^[n" history-search-forward
"^[p" history-search-backward

2)然后,我输入Ctrl + v后跟向上箭头,然后向下箭头,我得到了:

⮀ ~/.dotfiles ⮀ ⭠ ihacku ⮀ ^[OA
⮀ ~/.dotfiles ⮀ ⭠ ihacku ⮀ ^[OB

3)我将你的代码添加到我的.zshrc:

bindkey '^[OA' up-line-or-search                                                
bindkey '^[OB' down-line-or-search

注意:我在加载oh-my-zsh.sh后添加了这些行。

5)我采购了我的.zsh:

. ~/.zshrc 

最后我得到了预期的结果。非常感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

我认为您需要确保up-line-or-search"up-arrow"键绑定(以其字符代码为准)。在我自己的.zshrc(运行在Linux之上),我用

完成了这项工作
bindkey '^[[A' up-line-or-search
bindkey '^[[B' down-line-or-search

请注意,这些功能已分配给"^[[5~" ...