# ===== init completion autoload -Uz compinit && compinit -d ~/.zsh/cache/zcompdump zmodload -i zsh/complist # ===== setopts # allow completion from within a word or phrase setopt complete_in_word # always complete and display matches immediately after pressing setopt no_list_ambiguous # when completing from the middle of a word, move the cursor to the end. setopt always_to_end # always show completion menu on successive tab press. # (needs unsetopt menu_complete to work) setopt auto_menu # do not autoselect the first completion entry unsetopt menu_complete # ===== completion options # Enable completion caching, use rehash to clear zstyle ':completion:*' use-cache on zstyle ':completion:*' cache-path ~/.zsh/cache # List all files in the current directory when pressing tab on a empty input, # behave like complete-word otherwise. complete-word-or-complete-list-of-files() { if [[ $#BUFFER == 0 ]]; then BUFFER='ls ' CURSOR=3 zle list-choices zle backward-kill-word else zle complete-word fi } zle -N complete-word-or-complete-list-of-files bindkey '^I' complete-word-or-complete-list-of-files # Force a reload of the completion system if nothing matched; this fixes # installing a program and then trying to tab-completing its name. _force_rehash() { if (( CURRENT == 1 )); then rehash fi # we didn't really complete anything. return 1 } # list of completers to use zstyle ':completion:::::' completer \ _force_rehash _expand _complete _prefix _ignored _approximate #TODO: keep _prefix or not? # ignore case when trying to match typed characters zstyle ':completion:*:(^approximate):*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-}' # allow one mistake per three characters zstyle -e ':completion:*:approximate:*' max-errors \ 'reply=( $(( ($#PREFIX + $#SUFFIX) / 3 )) )' # expand shell wildcards to all matching files after zstyle ':completion:*:expand:*' tag-order all-expansions # keep prefixed unexpanded if possible zstyle ':completion:*:expand:*' keep-prefix on # Display all matching ambiguous components when completing multiple path # components. zstyle ':completion:*' list-suffixes on # TODO: keep list-suffixes or not? # ignore completion functions (until the _ignored completer) zstyle ':completion:*:functions' ignored-patterns '_*' # do not propose anything starting with '_' when offering typo corrections CORRECT_IGNORE='_*' # ===== completion appearance # use ls colors for completion zstyle ':completion:*' list-colors "${(@s.:.)LS_COLORS}" # Make the list prompt friendly zstyle ':completion:*:default' list-prompt '%SAt %p: Hit for more, or the character to insert%s' # Make the selection prompt friendly when there are a lot of choices zstyle ':completion:*:default' select-prompt '%SScrolling active: current selection at %p%s' # Display group (category) name (%d) (like 'external command', 'alias', etc.) in # bold. Also display a message if _approximate found errors and no matches # were found. zstyle ':completion:*' format ' %B%d%b:' zstyle ':completion:*:corrections' format ' %B%d%b (errors: %e)' zstyle ':completion:*:warnings' format ' %BNo matches for: %d%b' # display matches sorted into categories zstyle ':completion:*' group-name '' # always show menu and preselect the first option zstyle ':completion:*' menu select=1 _complete _ignored _approximate #TODO: keep? # make completion functions use the verbose style and form #zstyle ':completion:*' verbose yes # ===== completion commands # separate man pages by sections zstyle ':completion:*' separate-sections on # add simple colors to kill zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' # do not complete unwanted files with vim zstyle ':completion:*:*:vim:*:globbed-files' ignored-patterns \ '*.aux' '*.log' '*.pdf' '*.ps' '*.bbl' '*.blg' '*.out' '*-blx.bib' '*.run.xml' '*.dvi' \ '*.o' \ '*.pyc' \ '*.class' # only complete *.pdf with katarakt zstyle ':completion:*:*:katarakt:*:*' file-patterns '*.pdf *(-/)' # ===== completion fallback zle -C complete-files complete-word _generic zstyle ':completion:complete-files:*' completer _files bindkey '^F' complete-files