How to add fuzzy completion (e.g. Sublime Text palette) in ZSH

I changed the shell from bash to zsh, and I was wondering if this is possible for fuzzy complete commands, like using the Sublime Text palette. I think this concept of search, completion should be everywhere. It saves time.

An example :

cd dcmts -> cd Documents

cd dwnls/mnf -> cd Downloads/MyNewFolder

I saw the following project, and it is not very convincing.

zsh-fuzzy-match

And it seems you can define some settings or algorithms for setting the behavior of zsh on completion.

zstyle ':completion:*' completer _complete _match _approximate

zstyle ':completion:*:match:*' original only

zstyle ':completion:*:approximate:*' max-errors 10 numeric

The problem of the two previous solutions is that folders do not appear on top of the list when filling, when often what the user wants is required.

If you have some interesting .zshrc that doesn't allow for fuzzy searches, it would be interesting.

Thank you for your help.

+6
source share
3 answers

Can you give an example of folders when filling out the list above? It seems you have something in your configuration that breaks you. Zsh by default fills cd directories only:

 zsh -f # new Zsh with only default configs % zstyle ':completion:*' completer _complete _match _approximate % zstyle ':completion:*:approximate:*' max-errors 3 numeric % mkdir test && cd test % mkdir etc && touch et0 % autoload -U compinit && compinit % cd et0[TAB] # removes the 'et0' and replaces it with 'etc'. 

FWIW, to search and fill everywhere, try predict fooobar.com/questions/201619 / ... (I find it a little crazy ...)

In addition, in Zsh you can do things like:

 setopt auto_cd alias -d build=/home/foo/very/long/path/build # dir alias build # <-- changes into /home/foo/very/long/path/build 

Or simply

 zstyle ':completion:*' matcher-list 'm:{az}={AZ}' # match upper from lower case cd d/m[TAB] # just type the initial letter of each dir cd Downloads/MyNewFolder 

I mean, cd d/m requires less typing than cd dwnls/mnf ; -)

+3
source

I suggest you check out fzf , a universal fuzzy finder that can handle strings from standard input. This is written in Ruby, not a zsh script, so it may not be the way you want, but just like zsh-fuzzy-match, it sets the CTRL-T binding for your shell, and it's pretty simple to configure its behavior.

The following is an example of a GIF.

EDIT:

fzf is completely rewritten in Go and now comes with fuzzy completion support for zsh and bash.

+5
source

Try putting this

 zstyle ':completion:*' matcher-list 'r:[[:ascii:]]||[[:ascii:]]=** r:|=* m:{az\-}={AZ\_}' 

In your zshrc . It does exactly what you want and does it with zsh own completion system, and not with an external completion system.

+4
source

All Articles