ZSH选项卡完成 - 不填写第一个文件

时间:2010-08-04 21:23:25

标签: zsh

如果我在文件夹中有“something1”和“something2”文件,我如何使Z​​SH的标签完成只填写常用字符?例如,我输入:

som<Tab>

我希望它用“东西”填写,而不是“东西1”。

当前的zstyles:

zstyle ':completion:*' special-dirs true
zstyle ':completion::complete:*' use-cache on
zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s'
zstyle ':completion:*' menu select=1 _complete _ignored _approximate
zstyle -e ':completion:*:approximate:*' max-errors \
zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s'
zstyle ':completion:*::::' completer _expand _complete _ignored _approximate
zstyle -e ':completion:*:approximate:*' max-errors \
zstyle ':completion:*:expand:*' tag-order all-expansions
zstyle ':completion:*' verbose yes 
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d' 
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
# zstyle ':completion:*:processes' command 'ps -au$USER'
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
#zstyle ':completion:*:processes' command 'ps ax -o pid,s,nice,stime,args | sed "/ps/d"'
zstyle ':completion:*:*:kill:*:processes' command 'ps --forest -A -o pid,user,cmd'
zstyle ':completion:*:processes-names' command 'ps axho command' 
#zstyle ':completion:*:urls' local 'www' '/var/www/htdocs' 'public_html'
zstyle ':completion:*' hosts $(awk '/^[^#]/ {print $2 $3" "$4" "$5}' /etc/hosts | grep -v ip6- && grep "^#%" /etc/hosts | awk -F% '{print $2}') 
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' \
zstyle ':completion:*:functions' ignored-patterns '_*'
zstyle ':completion:*:*:*:users' ignored-patterns \
zstyle ':completion:*:scp:*' tag-order \
zstyle ':completion:*:scp:*' group-order \
zstyle ':completion:*:ssh:*' tag-order \
zstyle ':completion:*:ssh:*' group-order \
zstyle '*' single-ignored show

4 个答案:

答案 0 :(得分:0)

查看man zshoptions。它组织得非常好,所以所有的完成选项都在“完成”部分。我认为您正在寻找的选项是list_ambiguous。如果是这样,你只需要添加行

setopt list_ambiguous

到你的.zshrc

答案 1 :(得分:0)

好消息:这是完全可行的,你不需要担心zstyles。 (我相信。)坏消息:回答这个问题有点棘手。

有关您尝试解决的问题的特定zsh完成选项的详细说明,请参阅zsh用户指南的this specific section

此外,你可以做一个'男人zshoptions'并寻找特定于完成的选项。上面提到list_ambiguous的答案是答案的一部分,但我不相信它解决了整个问题。你需要问自己的一个关键问题是“在我第一次点击TAB并且zsh只插入常见字符后,我想要发生什么?”你可以让zsh在第二个 TAB印刷机上做很多不同的事情,甚至是第三个。使用ZSH完成选项的各种组合可以产生各种有用的结果。这一切都取决于你想要的。

祝你好运!

答案 2 :(得分:0)

如果您使用Zsh's new completion system,它就可以立即使用。将其添加到您的~/.zshrc文件中(或尝试将其粘贴到命令行中):

autoload -Uz compinit && compinit
bindkey '^I' complete-word

此后,如果您当前的工作目录中有两个文件something1something2,然后键入

% file s

,然后按 Tab ,它将完成

% file something

再次按 Tab ,它将显示

something1  something2

在命令行下。

然后您可以继续按 Tab 来循环浏览这两个。

答案 3 :(得分:0)

将此添加到 ~/.zshrc 对我有用:

setopt noautomenu
setopt nomenucomplete

https://serverfault.com/a/447549