How to add fuzzy completion (like Sublime Text palette) to ZSH

fuzzy-search, sublimetext, zsh

Solution

Can you give an example of folders doesn't appears on top of the list when completing? It seems you have something in your configuration breaking things for you. Zsh by default will only complete `cd` with directories:

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, for "searching and completing everywhere" consider trying `predict` https://stackoverflow.com/a/17230878/766289 (I find it a little insane...)

Also, 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 just

zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' # 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` ;-)

Problem

I changed by shell from bash to zsh and I was wondering if this was possible to fuzzy complete commands just like with the Sublime Text palette. I think that this concept of searching, completing must be everywhere. It's a huge time saving. Example: `cd dcmts -> cd Documents` `cd dwnls/mnf -> cd Downloads/MyNewFolder` I saw the following project and it's not really convincing. zsh-fuzzy-match And it's seems to be possible to define some settings or algorithms to configure the behaviour 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 doesn't appears on top of the list when completing while it's often what the user wants. If you have any interesting `.zshrc` that statisfy fuzzy search, it would be interesting. Thanks for your help.

Original source

Related problems