5

I've just started using the Command-T plugin for vim, and it rocks. In case you haven't heard of it, it allows you to type something like this:

Sb

to select Something.hs-boot from the list

src/project/Control/Whatever/Foobs.hs
src/project/Control/Whatever/Something.hs-boot
src/project/Control/Whatever/Something.hs

And so on.

I was wondering if I could use a similar autocompletion style with zsh. I understand that the shell completion couldn't be nearly as extensive as the vim completion because the shell complition probably shouldn't be searching the entire system every time you type a letter, but is there some sort of similar completion where I could at least type

s/p/c/w/Sb<tab>

and get an effect similar to the one above?

I've heard that zsh has a pretty well-programmable autocomplete functionality, but my shell-fu is fairly weak.

Anybody know how to set this up?

2 Answers 2

1

To complete partial paths, it's enough to just init the completion system (at least on my system, using zsh v4.3.17):

autoload -U compinit && compinit
zmodload zsh/complist

If you want to get a little more fancy, you can make the matching case-insensitive:

zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'

Update 1:

I don't know if you can do Command-T-style autocompletion ... but as zsh has to get all matches before it displays something, doing this on-the-fly, especially somewhere that has a lot of subdirectories/files, might not be feasible.

You could however use:

**/*thing <Tab>

The ** matches all files & subdirectories of the current directory.

Idea: If it does not have to be an up-to-date list of files, you could potentially write a completion function that uses the output of locate (i.e. a pre-computed file list)

Update 2: https://github.com/junegunn/fzf#fuzzy-completion-for-bash-and-zsh

1

Another interesting alternative is to use something like fasd.

1
  • I second the recommendation for fasd. With fasd, you could simply type v Sb and it would open the file matching 'Sb' best in vim, according to time elapsed and frequency of edits of that file. Feb 9, 2013 at 5:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .