Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zsh autocomplete from the middle of filename

Tags:

zsh

is it possible that zsh complete the whole file name from partial words of correct filename ? For example, there are (helloABC, helloabc, helloworld) under this folder, and I want to type only (oab + tab) to get (helloABC, helloabc.)

like image 887
sailplaneTW Avatar asked Mar 24 '14 02:03

sailplaneTW


1 Answers

Yes this is possible. It can be enabled in the zsh completion system.

Adding these lines to your .zshrc will give you this feature:

zstyle ':completion:*' completer _complete
zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' '+l:|=* r:|=*'
autoload -Uz compinit
compinit
  • _completer gives normal completion behaviour

  • 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' '+l:|=* r:|=*' takes care of case-insensive matching and that matching may occur on both sides of the current word (that is matching from the middle part of a filename).

Note: Some of these or similar lines may already be in your ~/.zshrc. In that case you may have to edit them:

  • if not already there _complete has to be added to the line starting with the definition for completer

  • If already present the rule for case-insensitivity might look different, for example m:{A-Za-z}={a-zA-Z}, which you can either be replaced or left as is.

    +l:|=* r:|=* has to come immediatelly after the rule for case-insensitivity (it may also work if there are only rules starting with + between those two rules, but I did only check some basic combinations, which worked)

like image 161
Adaephon Avatar answered Dec 18 '22 19:12

Adaephon