ZSH的标签补全-不要填写第一个文件

10
如果我在一个文件夹中有文件"something1"和"something2",如何让ZSH的标签自动完成仅填充共同的字符呢?例如,我会输入:
som<Tab>

我希望它填充为"something"而不是"something1"。

当前的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

如果您在命令提示符下输入 zstylegrep zstyle ~/.zshrc,会得到什么结果?我有一个设置为 zstyle ':completion:*' menu select=0,虽然我不认为它会影响您所询问的内容,但我确实得到了您所寻求的行为。 - Dennis Williamson
尝试过了,似乎没有成功。 - victor
6个回答

3

1

删除行:

setopt menu_completion

从你的.zshrc文件中读取,并且使用填写不含歧义的部分应该可以正常运行。

0
在你的zshrc文件中(位于~/.zshrc),粘贴以下行:zstyle ':autocomplete:*' insert-unambiguous yes 如果以前设置为no,则更改为上述行将起作用。

0

如果您使用Zsh的新完成系统,它将直接开箱即用。将以下内容添加到您的~/.zshrc文件中(或者为了尝试它,只需将其粘贴到命令行中):

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

接下来,如果你的当前工作目录中有两个文件something1something2,并且你输入以下命令:

% file s

然后按下Tab,它会自动完成为

% file something

再次按下 Tab 将会显示

something1  something2

在命令行下。

然后,您可以不断按 Tab 键来循环这两个选项。


-1

好消息:这完全可行,而且您不必担心zstyles。(我相信。)坏消息:回答有点棘手。

关于您要解决的问题相关的特定zsh完成选项的优秀解释可以在zsh用户指南(此特定部分)中找到。

此外,您可以执行“man zshoptions”并查找特定于完成选项的选项。上面提到的list_ambiguous是答案的一部分,但我不认为它涵盖了整个情况。您需要问自己的一个关键问题是“当我第一次按TAB并且zsh仅插入公共字符时,我希望发生什么?”您可以让zsh在第二个甚至第三个TAB按下时执行许多不同的操作。使用各种ZSH完成选项的组合可以产生各种有用的结果。这都取决于您想要什么。

祝你好运!


-1

查看 man zshoptions。它非常好组织,所有的自动补全选项都在“Completion”部分中。我认为你要找的选项是 list_ambiguous。如果是这样,你只需要在 .zshrc 文件中添加以下行:

setopt list_ambiguous


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接