Skip to content

🤖 Real-time type-ahead completion for Zsh. Asynchronous find-as-you-type autocompletion.

License

Notifications You must be signed in to change notification settings

seinaville/zsh-autocomplete

 
 

Repository files navigation

zsh-autocomplete

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.

file-search

Other Features

Besides live autocompletion, zsh-autocomplete comes with many more useful completion features.

Optimized completion config

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.

Live history search

Press Ctrl+R or Ctrl+S to do an interactive, multi-line, fuzzy history search.

history-search

History menu

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.

history menu

Multi-selection

Press Ctrl+Space in the completion menu or the history menu to insert more than one item.

multi-select

Recent dirs completion

Works out of the box with zero configuration, but also supports zsh-z, zoxide, z.lua, rupa/z.sh, autojump and fasd.

recent dirs

Additional, context-sensitive completions

Press Shift+Tab to insert:

unambiguous

requoted

alias expansion

Key Bindings

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

Completion Menu

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

History Menu

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

Requirements

Recommended:

  • Zsh 5.8 or later.

Minimum:

  • Zsh 5.3 or later.

Installation

  1. git clone this repo.
  2. Add to your ~/.zshrc file, before any calls to compdef:
    source path/to/zsh-autocomplete.plugin.zsh
  3. Remove any calls to compinit from your ~/.zshrc file.

Updating

  1. cd into zsh-autocomplete's directory.
  2. Do git pull.

As a Plugin

zsh-autocomplete should work as a plugin with most frameworks & plugin managers. Please refer to your framework's/plugin manager's documentation for instructions.

Settings

To change your settings, just copy-paste any of the code below to your ~/.zshrc file.

⚠️ Note that while most of these settings use the :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

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

⚠️ Note that, unlike most other settings, changing 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.

Change other key bindings

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

Start autocompletion in history search mode

To start each new command line as if Ctrl+R has been pressed:

zstyle ':autocomplete:*' default-context history-incremental-search-backward

Wait for a minimum amount of time

To suppress autocompletion until you have stopped typing for a certain number of seconds:

zstyle ':autocomplete:*' min-delay .3  # 300 milliseconds

Wait for a minimum amount of input

To suppress autocompletion until a minimum number of characters have been typed:

zstyle ':autocomplete:*' min-input 3

Ignore certain inputs

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.

Disable certain completions

To disable, for example, ancestor directories, recent directories and recent files:

zstyle ':completion:*:complete:*:' tag-order \
  '! ancestor-directories recent-directories recent-files' -

⚠️ Note the additional : at the end of the namespace selector and the - as the last value.

Change the order of completions

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

⚠️ Note the additional : at the end of the namespace selector.

Show more/less help text

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

Change the "Partial list" message

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"

Use your own completion config

To disable zsh-autocomplete's pre-packaged completion config completely:

zstyle ':autocomplete:*' config off

Author

© 2020 Marlon Richert

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

🤖 Real-time type-ahead completion for Zsh. Asynchronous find-as-you-type autocompletion.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%