zsh:强制单个tab补全

5

最近我从bash切换到了zsh。如何实现以下的tab键自动完成行为:

输入前几个字母,然后按下TAB键。自动完成输入并显示所有可选项/替代方案。

当前的行为是这样的:

# ls .m*
  .mysql_history  .matlab  .matplotlib  .mono  .mozilla
# cd .m<TAB>
  .matlab/  .matplotlib/  .mono/  .mozilla/
# cd .mo<TAB>
  .mono/  .mozilla/
# cd .ma<TAB><TAB> (here two tabs are necessary: the first one completes to .mat, 
                    the second one show .matlab and .matplotlib)

我希望能够在最后一个案例中去掉第二个选项卡。使用zsh的完成系统可以实现这个目的吗?

这是我目前的.zshrc文件:

HISTFILE=~/.histfile
HISTSIZE=10000
SAVEHIST=1000

# Options
setopt autocd

# Aliases
alias ls='ls --color -h --group-directories-first'
alias ll='ls -laF --color -h --group-directories-first'
alias la='ls -A --color -h --group-directories-first'


alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'

# Prompt
PS1="[%n@%m]%F{112}[%~]%f# "

# Enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
fi

# Set vim mode
bindkey -v

# Key bindings
# Vi insert mode
bindkey -M viins 'jj' vi-cmd-mode
bindkey -M vicmd '^i' vi-down-line-or-history
bindkey -M vicmd '^k' vi-up-line-or-history

# Vi command mode
bindkey -M vicmd 'l' vi-forward-char
bindkey -M vicmd '^l' vi-forward-word
bindkey -M vicmd 'j' vi-backward-char
bindkey -M vicmd '^j' vi-backward-word
bindkey -M vicmd 'h' vi-insert
bindkey -M vicmd 'i' vi-down-line-or-history
bindkey -M vicmd 'k' vi-up-line-or-history

# Environment variables
export TERM=xterm-256color

# Completion
zstyle :compinstall filename '/home/jeschma/.zshrc'

autoload -Uz compinit
compinit
1个回答

6

好的,我发现zsh选项listambiguous是默认设置的。我只需要在我的zshrc中插入unsetopt listambiguous,我的问题就解决了。现在每次按下单个TAB键时,可能的补全都会被显示出来。


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