zsh:强制单选项卡完成

标签 zsh zshrc zsh-completion

我最近从 bash 切换到 zsh。如何实现以下选项卡完成行为:

输入第一个字母,然后按 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)

在最后一种情况下,我想去掉第二个选项卡。 zshs 完成系统可以做到这一点吗?

这是我现在的 .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

最佳答案

好的,我发现 zsh 选项 listambiguous是默认设置的。我刚插入 unsetopt listambiguous进入我的 zshrc,我的问题就解决了。现在可能的完成显示为单个 TAB每次都按。

关于zsh:强制单选项卡完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15132028/

相关文章:

git - 忽略 zsh git autocomplete 中的 ORIG_HEAD

python - Anaconda 更新后 Zsh "(eval):61: = not found"错误

zsh - 当程序有子命令时完成

bash - 如何在 Zsh 缩写后移动光标?

zsh - 从文件中生成 zsh 完整参数

git - 设置 DotBot 和抗原

shell - 如何对命令行标志进行多字大括号扩展

macos - zsh - 使用默认值读取用户输入 - 空输入不为空?

flutter - xcrun : error: invalid active developer path, problem after zsh update for flutter

macos - zsh:在 MacOS Monterey 上找不到命令