zsh-autocomplete
adds real-time type-ahead autocompletion to Zsh. Find as you type, then
press Tab to insert the top completion, Shift+Tab to insert the
bottom one, or ↓/PgDn to select another completion.
Besides live autocompletion, zsh-autocomplete
comes with many more useful completion features.
Zsh's completion system is powerful, but hard to configure. So, zsh-autocomplete
does it for you,
while providing a manageable list of settings for changing the defaults.
Press Ctrl+R or Ctrl+S to do an interactive, multi-line, fuzzy history search.
Press ↑ or PgUp to browse the last 16 history items. If the command line is not empty, then it will instead list the 16 most recent fuzzy matches.
Press Ctrl+Space in the completion menu or the history menu to insert more than one item.
Works out of the box with zero configuration, but also supports zsh-z
, zoxide
, z.lua
,
rupa/z.sh
, autojump
and fasd
.
Press Shift+Tab to insert:
Key(s) | Action | Widget |
---|---|---|
any | Show completions (asynchronously) | _list_choices |
Tab | Insert top completion | complete-word |
Shift+Tab | Insert bottom completion | expand-word |
Ctrl+Space | Show full completion menu | list-expand |
↓ | Enter completion menu or move cursor down (in multi-line buffer) | down-line-or-select |
PgDn | Enter completion menu (always) | menu-select |
↑ | Open history menu or move cursor up (in multi-line buffer) | up-line-or-search |
PgUp | Open history menu (always) | history-search |
Ctrl+R | Search history from newest to oldest | history-incremental-search-backward |
Ctrl+S | Search history from oldest to newest | history-incremental-search-forward |
Key(s) | Action |
---|---|
↑/↓/←/→ | Change selection |
Enter | Exit menu & execute command line |
Alt+Enter | Exit menu |
Ctrl+Space | Multi-select |
Alt+Shift+, | Beginning of menu |
Alt+Shift+. | End of menu |
PgUp | Page up |
PgDn | Page down |
Alt+B | Backward one group |
Alt+F | Forward one group |
Home | Beginning of line |
End | End of line |
Key(s) | Action |
---|---|
↑/↓ | Change selection |
←/→ | Exit menu & move cursor |
Enter | Exit menu & execute command line |
Alt+Enter | Exit menu |
Ctrl+Space | Multi-select |
Alt+Shift+, | Beginning of menu |
Alt+Shift+. | End of menu |
Recommended:
- Zsh 5.8 or later.
Minimum:
- Zsh 5.3 or later.
git clone
this repo.- Add to your
~/.zshrc
file, before any calls tocompdef
:source path/to/zsh-autocomplete.plugin.zsh
- Remove any calls to
compinit
from your~/.zshrc
file.
cd
intozsh-autocomplete
's directory.- Do
git pull
.
zsh-autocomplete
should work as a plugin with most frameworks & plugin managers. Please refer to
your framework's/plugin manager's documentation for instructions.
To change your settings, just copy-paste any of the code below to your ~/.zshrc
file.
:autocomplete:
namespace, some of them use
:completion:
. This is because the latter are managed by Zsh's own completion system, whereas the
former are unique to zsh-autocomplete
.
- Change Tab behavior
- Change other key bindings
- Start autocompletion in history search mode
- Wait for a minimum amount of time
- Wait for a minimum amount of input
- Ignore certain inputs
- Disable certain completions
- Change the order of completions
- Show more/less help text
- Change the "Partial list" message
- Use your own completion config
By default, Tab insert the top completion, Shift+Tab inserts the bottom completion, and ↓ activates menu selection.
To make Tab first insert any common substring, before inserting full completions:
zstyle ':autocomplete:tab:*' insert-unambiguous yes
To make Tab or Shift+Tab activate menu selection:
zstyle ':autocomplete:tab:*' widget-style menu-select
To make Tab and Shift+Tab cycle completions without using menu selection:
zstyle ':autocomplete:tab:*' widget-style menu-complete
To make Tab try Fzf's completion before using Zsh's:
zstyle ':autocomplete:tab:*' fzf-completion yes
widget-style
at runtime has no effect and
changing fzf-completion
at runtime will not function correctly. These settings can be changed in
your ~/.zshrc
file only.
widget-style
, insert-unambiguous
and fzf
are mutually compatible and can be used in parallel.
Key bindings other than Tab or Shift+Tab can be overridden with
the bindkey
command, if you do so after sourcing zsh-autocomplete
. To make this easier,
zsh-autocomplete
defines an associative array $key
that you can use:
source path/to/zsh-autocomplete.plugin.zsh
# The following lines revert the given keys back to Zsh defaults:
bindkey $key[Up] up-line-or-history
bindkey $key[Down] down-line-or-history
bindkey $key[ControlSpace] set-mark-command
bindkey -M menuselect $key[Return] accept-line
To start each new command line as if Ctrl+R has been pressed:
zstyle ':autocomplete:*' default-context history-incremental-search-backward
To suppress autocompletion until you have stopped typing for a certain number of seconds:
zstyle ':autocomplete:*' min-delay .3 # 300 milliseconds
To suppress autocompletion until a minimum number of characters have been typed:
zstyle ':autocomplete:*' min-input 3
To not trigger autocompletion for input that matches a pattern:
# This example matches any input word consisting of two or more dots (and no other chars).
zstyle ':autocomplete:*' ignored-input '..##'
The pattern syntax supported here is that of Zsh's extended glob operators.
To disable, for example, ancestor directories, recent directories and recent files:
zstyle ':completion:*:complete:*:' tag-order \
'! ancestor-directories recent-directories recent-files' -
:
at the end of the namespace selector and the -
as the last value.
To list certain completions in a particular order before all other completions:
zstyle ':completion:*:complete:*:' group-order \
options arguments values local-directories files builtins history-words
:
at the end of the namespace selector.
To show auto-generated command descriptions:
zstyle ':completion:*' extra-verbose yes
To show command descriptions only when you press Ctrl+Space:
zstyle ':completion:list-expand:*' extra-verbose yes
To hide all descriptions:
zstyle ':completion:*' verbose no
To alter the message shown when the list of completions does not fit on screen:
local hint=$'%{\e[02;39m%}' kbd=$'%{\e[22;39m%}' end=$'%{\e[0m%}'
zstyle ':autocomplete:*:too-many-matches' message \
"${hint}(partial list; press ${kbd}Ctrl${hint}+${kbd}Space$hint to expand)$end"
To disable zsh-autocomplete
's pre-packaged completion config completely:
zstyle ':autocomplete:*' config off
© 2020 Marlon Richert
This project is licensed under the MIT License. See the LICENSE file for details.