1

我喜欢 ZSH 中有一个非常好的功能。当您键入 ! 字符后跟一个单词 + TAB 键,它使 shell 拉起最后一个以单词开头的命令,后面跟着 ! 并扩展它;例如:

% !ssh

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

 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

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

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

@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 

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

4

1 回答 1

1

我认为你需要确保它up-line-or-search绑定到"up-arrow"键(无论它的字符代码)。在我自己.zshrc(在 Linux 之上运行),我完成了这个

bindkey '^[[A' up-line-or-search
bindkey '^[[B' down-line-or-search

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

于 2013-05-28T10:26:22.143 回答