Wie erhalte ich die Tab-Vervollständigung von zsh zu "vi **/foo" um die erste Datei, die mit "foo*" übereinstimmt, irgendwo im aktuellen Verzeichnis abzugleichen und zu vervollständigen?

Wie erhalte ich die Tab-Vervollständigung von zsh zu "vi **/foo" um die erste Datei, die mit "foo*" übereinstimmt, irgendwo im aktuellen Verzeichnis abzugleichen und zu vervollständigen?

Wie erreiche ich, dass die Tab-Vervollständigung von zsh die erste passende Datei in einem beliebigen Unterverzeichnis des aktuellen Verzeichnisses findet cat **/foo<TAB>und vervollständigt ?foo*

Tun Sie dies beispielsweise, während Sie sich in einem neuen Testverzeichnis befinden: (auch dies ist zsh)

% mkdir aaa bbb ccc
% touch aaa/foo bbb/foo ccc/foo
% cat **/f<TAB>

Wenn ich auf die letzte Zeile klicke, <TAB>soll mein Bildschirm am Ende so aussehen:

% cat aaa/foo_                 # filled in the first match; "_" is the cursor
aaa/foo  bbb/foo  ccc/foo      # and here is the list of all matches

Ich habe es versucht setopt GLOB_COMPLETE, aber es hat nicht das gewünschte Ergebnis gebracht.

Antwort1

Fügen Sie Ihrer Datei Folgendes hinzu ~/.zshrc(oder fügen Sie es in die Befehlszeile ein, um es auszuprobieren):

# Load Zsh's new completion system.
autoload -Uz compinit && compinit

# Bind Tab to complete-word instead of 
# expand-or-complete. This is required for 
# the new completion system to work 
# correctly.
bindkey '^I' complete-word

# Add the _match completer.
# We add it after _expand & _complete, so it 
# will get called only once those two have 
# failed.
# _match_ completes patterns only, which 
# _expand can do, too, (which is why we call 
# _match_ only when _expand & _complete 
# fail), but _match adds an extra * at the 
# cursor position. Without that, the pattern 
# **/f would not match {aaa,bbb,ccc}/foo
zstyle ':completion:*' completer \
    _expand _complete _match _ignored

# Let all possible completions for a partial 
# path be listed, rather than just the first 
# one.
zstyle ':completion:*' list-suffixes true

Wenn Sie dann eingeben cat **/fund drücken Tab, erhalten Sie die folgende Ausgabe:

% cat aaa/foo
aaa/foo  bbb/foo  ccc/foo
**/f

Dokumentation:

Siehe auch:Ein Benutzerhandbuch zur Z-Shell: Vervollständigung, alt und neu

verwandte Informationen