Skip to content

Instantly share code, notes, and snippets.

@olets
Created July 28, 2024 03:45
Show Gist options
  • Save olets/e8e2228bd6d0fec38532519523320087 to your computer and use it in GitHub Desktop.
Save olets/e8e2228bd6d0fec38532519523320087 to your computer and use it in GitHub Desktop.
zsh completion setup
# If a completion is performed with the cursor within a word, and a full completion is inserted, the cursor is moved to the end of the word. That is, the cursor is moved to the end of the word if either a single match is inserted or menu completion is performed.
setopt always_to_end
# Automatically use menu completion after the second consecutive request for completion, for example by pressing the tab key repeatedly. This option is overridden by MENU_COMPLETE.
setopt auto_menu
# If unset, the cursor is set to the end of the word if completion is started. Otherwise it stays there and completion is done from both ends.
setopt complete_in_word
# On an ambiguous completion, instead of listing possibilities or beeping, insert the first match immediately. Then when completion is requested again, remove the first match and insert the second match, etc. When there are no more matches, go back to the first one again. reverse-menu-complete may be used to loop through the list in the other direction. This option overrides AUTO_MENU.
unsetopt menu_complete
# Show completion suggestions in a menu
zstyle ':completion:*:*:*:*:*' menu select
# Make completion case insensitive, not distinguish between hyphens and underscore, and complete as prefix or suffix
zstyle ':completion:*' matcher-list 'm:{a-zA-Z-_}={A-Za-z_-} l:|=* r:|=*'
# Use the completion cache
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path $ZSH_CACHE_DIR
# Color code completion suggestions
zstyle ':completion:*' list-colors ''
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
# load https://github.com/zsh-users/zsh-completions in whatever way your setup loads plugins
# load other completion plugins, if any
# run compinit if your setup doesn't run it for you
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment