https://github.com/marlonrichert/zsh-autocomplete
🤖 Real-time type-ahead completion for Zsh. Asynchronous find-as-you-type autocompletion.
https://github.com/marlonrichert/zsh-autocomplete
asynchronous autocomplete autocompletion completion non-blocking typeahead typeahead-completions zsh zsh-autocomplete zsh-completion zsh-plugin zsh-plugins
Last synced: about 1 year ago
JSON representation
🤖 Real-time type-ahead completion for Zsh. Asynchronous find-as-you-type autocompletion.
- Host: GitHub
- URL: https://github.com/marlonrichert/zsh-autocomplete
- Owner: marlonrichert
- License: mit
- Created: 2020-04-24T11:31:17.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2025-04-24T05:11:56.000Z (about 1 year ago)
- Last Synced: 2025-05-08T23:44:12.367Z (about 1 year ago)
- Topics: asynchronous, autocomplete, autocompletion, completion, non-blocking, typeahead, typeahead-completions, zsh, zsh-autocomplete, zsh-completion, zsh-plugin, zsh-plugins
- Language: Shell
- Homepage:
- Size: 4.25 MB
- Stars: 5,788
- Watchers: 23
- Forks: 169
- Open Issues: 41
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-zsh-plugins - autocomplete - Automatically lists completions as you type and provides intuitive keybindings for selecting and inserting them. (Plugins / ZSH on Windows)
- fucking-awesome-zsh-plugins - autocomplete - Automatically lists completions as you type and provides intuitive keybindings for selecting and inserting them. (Plugins / ZSH on Windows)
- my-awesome - marlonrichert/zsh-autocomplete - blocking,typeahead,typeahead-completions,zsh,zsh-autocomplete,zsh-completion,zsh-plugin,zsh-plugins pushed_at:2026-04 star:6.6k fork:0.2k 🤖 Real-time type-ahead completion for Zsh. Asynchronous find-as-you-type autocompletion. (Shell)
- awesome-rainmana - marlonrichert/zsh-autocomplete - 🤖 Real-time type-ahead completion for Zsh. Asynchronous find-as-you-type autocompletion. (Shell)
- StarryDivineSky - marlonrichert/zsh-autocomplete - autocomplete 是一个为 Zsh 设计的实时异步自动补全插件,旨在提升命令行输入效率。项目核心功能是实现“边输入边查找”的异步补全机制,用户在输入命令时,系统会自动在后台搜索匹配的补全选项,避免传统同步补全导致的卡顿问题。它基于 Zsh 5.0 及以上版本开发,支持主流终端框架如 Oh My Zsh,并兼容多种 Shell(如 Zsh、Fish、Bash)。 该项目通过异步处理技术优化性能,补全过程不会阻塞当前终端操作,输入时保持流畅响应。其工作原理是利用 Zsh 的原生补全系统,结合自定义的异步任务队列,将补全逻辑拆分为前台输入和后台搜索两个独立流程。用户可自定义补全规则,例如通过编写补全函数或集成外部工具(如 fzf)扩展功能。相比传统插件,它无需依赖额外依赖项,仅需安装 Zsh 5.0 即可运行。 项目特色包括:1. 实时性——输入时即时显示补全建议;2. 异步性——补全任务在后台运行,不影响输入速度;3. 可扩展性——支持自定义补全函数和主题样式;4. 轻量级——无额外依赖,安装简单(通过 Oh My Zsh 安装只需一行命令)。此外,它还兼容主流插件管理框架,如 Zsh 的 autosuggestions 插件,并通过性能优化(如减少进程调用)提升运行效率。用户可通过配置文件或命令行参数灵活调整补全行为,适合需要高效命令行操作的开发者或系统管理员使用。 (终端 / 资源传输下载)
README
# Autocomplete for Zsh
This plugin for Zsh adds real-time type-ahead autocompletion to your command line, similar to what
you find in desktop apps. While you type on the command line, available completions are listed
automatically; no need to press any keyboard shortcuts. Press Tab to insert the top
completion or ↓ to select a different one.
Additional features:
* Out-of-the-box configuration of Zsh's completion system
* Multi-line history search
* Completion of recent directories
* Useful [keyboard shortcuts](#keyboard-shortcuts)
* Easy to [configure](#configuration)
> Enjoy using this software? [Become a sponsor!](https://github.com/sponsors/marlonrichert) 💝
## Requirements
Recommended:
* Tested to work with [Zsh](http://zsh.sourceforge.net) 5.8 and newer.
Minimum:
* Should theoretically work with Zsh 5.4, but I'm unable to test that.
## Installation & setup
> Note: In this manual, `%` represents the command line prompt. If you see it in front of a command,
> it means you should run it on the command line, not put it in a script.
First, install Autocomplete itself. Here are some way to do so:
* To use only releases (instead of the `main` branch), install `zsh-autocomplete` with a package
manager. As of this writing, this package is available through Homebrew, Nix, `pacman`, Plumage,
and (as `app-shells/zsh-autocomplete`) Portage.
* To always use the latest commit on the `main` branch, do one of the following:
* Use `pacman` to install `zsh-autocomplete-git`.
* Use a Zsh plugin manager to install `marlonrichert/zsh-autocomplete`. (If you don't have a
plugin manager yet, I recommend using [Znap](https://github.com/marlonrichert/zsh-snap).)
* Clone the repo directly:
```sh
% git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
```
After installing, make the following modifications to your shell config:
* In your `.zshrc` file:
* Remove any calls to `compinit`.
* Add near the top, _before_ any calls to `compdef`:
```sh
source /path/to/zsh-autocomplete/zsh-autocomplete.plugin.zsh
```
* When using **Ubuntu,** add to your `.zshenv` file:
```sh
skip_global_compinit=1
```
* When using **Nix,** add to your `home.nix` file:
```
programs.zsh.enableCompletion = false;
```
Finally, restart your shell. Here's two ways to do so:
* Open a new tab or window in your terminal.
* Replace the current shell with a new one:
```sh
% exec zsh
```
### Updating
If you installed manually, run:
```sh
% git -C ~autocomplete pull
```
Otherwise, simply use your package manager or plugin manager's update mechanisms.
### Uninstalling
1. Revert the actions you took to [install](#installation).
1. Restart your shell.
## Keyboard shortcuts
| `main` | `emacs` | `vicmd` | On the command line | In the menus
| ---: | ---: | ---: | :--- | :---
| Enter
Return | | | | Exit menu text search or exit menu
| Tab | | | Insert first listed menu item | Exit menu text search or exit menu
| ShiftTab | | | Insert substring occurring in all listed completions | Exit menu text search or exit menu
| ↓ | CtrlN | J | Cursor down or enter completion menu | Change selection
| ↑ | CtrlP | K | Cursor up or enter [history menu](#history-menu) | Change selection
| Alt↓ | AltN | CtrlN | Enter completion menu | Next section
| Alt↑ | AltP | CtrlP | Enter history menu | Previous section
| PgDn | | | | Page down
| PgUp | | | | Page up
| | CtrlX / | | Toggle recent path search |
| | CtrlR | / | Toggle history search | Start menu text search or go to previous match
| | CtrlS | ? | Start menu text search | Start menu text search or go to next match
| | CtrlSpace | V | Toggle selection mode | Add another item
| | Ctrl-
Ctrl/ | U | | Undo last item
| | CtrlG | | | Undo all added items
### Caveats
* `main` is whichever keymap was aliased to `main` when Autocomplete was sourced.
* By default, this is `emacs`.
* If you run `bindkey -v` _before_ sourcing Autocomplete, then `main` will be `viins` when
Autocomplete installs keybindings.
* Plugins or other scripts that you load _after_ loading Autocomplete may override these bindings.
If you find that some shortcuts don't work as expected, then you can fix them by
* changing the order in which you source your plugins or by
* running [`bindkey` commands](#reassign-keys) in your dotfiles _after_ you source your plugins.
* Depending on your terminal, not all keybindings might be available to you.
* Instead of Alt, your terminal might require you to press Escape,
Option or Meta.
* In the menus, the bindings listed under `vicmd` require you to press Alt for each,
instead of just once.
* The bindings listed under `emacs` and `vicmd` are always both active in the menus, no matter which
keymap you actually use. This is a limitation of Zsh.
* What any other keys do while you're in a menu depends on the keymap from which you opened the
menu. See the Zsh manual section on [menu
selection](https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#Menu-selection) for more info.
## Configuration
The following are the most commonly requested ways to configure Autocomplete's behavior. To use any
of these, add the code shown to your `.zshrc` file and modify it there, then restart you shell.
### Reassign keys
You can use [Zsh's `bindkey`
command](https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Zle-Builtins), _after_ loading
Autocomplete, to customize your keybindings. Below are some examples of what you can do with this.
#### Make Tab and ShiftTab cycle completions on the command line
This makes Tab and ShiftTab, when pressed on the command line,
cycle through listed completions, without changing what's listed in the menu:
```sh
bindkey '^I' menu-complete
bindkey "$terminfo[kcbt]" reverse-menu-complete
```
#### Make Tab and ShiftTab go to the menu
This makes Tab and ShiftTab, when pressed on the command line,
enter the menu instead of inserting a completion:
```sh
bindkey '^I' menu-select
bindkey "$terminfo[kcbt]" menu-select
```
#### Make Tab and ShiftTab change the selection in the menu
This makes Tab and ShiftTab move the selection in the menu right
and left, respectively, instead of exiting the menu:
```sh
bindkey -M menuselect '^I' menu-complete
bindkey -M menuselect "$terminfo[kcbt]" reverse-menu-complete
```
#### Make ← and → always move the cursor on the command line
This makes ← and → always move the cursor on the command line, even when you
are in the menu:
```sh
bindkey -M menuselect '^[[D' .backward-char '^[OD' .backward-char
bindkey -M menuselect '^[[C' .forward-char '^[OC' .forward-char
```
#### Make Enter always submit the command line
This makes Enter always submit the command line, even when you are in the menu:
```sh
bindkey -M menuselect '^M' .accept-line
```
#### Restore Zsh-default history shortcuts
This restores the default Zsh keybindings for history control:
```sh
bindkey -M emacs \
"^[p" .history-search-backward \
"^[n" .history-search-forward \
"^P" .up-line-or-history \
"^[OA" .up-line-or-history \
"^[[A" .up-line-or-history \
"^N" .down-line-or-history \
"^[OB" .down-line-or-history \
"^[[B" .down-line-or-history \
"^R" .history-incremental-search-backward \
"^S" .history-incremental-search-forward \
#
bindkey -a \
"^P" .up-history \
"^N" .down-history \
"k" .up-line-or-history \
"^[OA" .up-line-or-history \
"^[[A" .up-line-or-history \
"j" .down-line-or-history \
"^[OB" .down-line-or-history \
"^[[B" .down-line-or-history \
"/" .vi-history-search-backward \
"?" .vi-history-search-forward \
#
```
### Pass arguments to `compinit`
If necessary, you can let Autocomplete pass arguments to `compinit` as follows:
```sh
zstyle '*:compinit' arguments -D -i -u -C -w
```
### First insert the common substring
You can make any completion widget first insert the longest sequence of characters
that will complete to all completions shown, if any, before inserting actual completions:
```zsh
# all Tab widgets
zstyle ':autocomplete:*complete*:*' insert-unambiguous yes
# all history widgets
zstyle ':autocomplete:*history*:*' insert-unambiguous yes
# ^S
zstyle ':autocomplete:menu-search:*' insert-unambiguous yes
```
#### Insert prefix instead of substring
When using the above, if you want each widget to first try to insert only the longest _prefix_ that
will complete to all completions shown, if any, then add the following:
```zsh
zstyle ':completion:*:*' matcher-list 'm:{[:lower:]-}={[:upper:]_}' '+r:|[.]=**'
```
Note, though, that this will also slightly change what completions are listed initially. This is a
limitation of the underlying implementation in Zsh.
### Customize common substring message
You can customize the way the common substring is presented. The following sets the presentation to
the default:
```zsh
builtin zstyle ':autocomplete:*:unambiguous' format \
$'%{\e[0;2m%}%Bcommon substring:%b %0F%11K%d%f%k'
```
`%d` will be replaced with the common substring. Additionally, the following [Zsh prompt escape
sequences](https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html#Visual-effects) are
supported for adding visual effects:
* `%B`: bold
* `%F`: foreground color
* `%K`: background color
* `%S`: `terminfo` "standout"
* `%U`: underline
* `%{...%}`: arbitrary [ANSI escape
sequence](https://en.wikipedia.org/wiki/ANSI_escape_code#Select_Graphic_Rendition_parameters)
### Make Enter submit the command line straight from the menu
By default, pressing Enter in the menu search exits the search and
pressing it otherwise in the menu exits the menu. If you instead want to make
Enter _always_ submit the command line, use the following:
```zsh
bindkey -M menuselect '\r' .accept-line
```
### Add or don't add a space after certain completions
When inserting a completion, a space is added after certain types of
completions. The default list is as follows:
```zsh
zstyle ':autocomplete:*' add-space \
executables aliases functions builtins reserved-words commands
```
Modifying this list will change when a space is inserted. If you change the
list to `'*'`, a space is always inserted. If you put no elements in the list,
then a space is never inserted.
### Start each command line in history search mode
This will make Autocomplete behave as if you pressed CtrlR at the start of
each new command line:
```zsh
zstyle ':autocomplete:*' default-context history-incremental-search-backward
```
### Wait with autocompletion until typing stops for a certain amount of seconds
Normally, Autocomplete fetches completions after you stop typing for about 0.05 seconds. You can
change this as follows:
```zsh
zstyle ':autocomplete:*' delay 0.1 # seconds (float)
```
### Wait longer before timing out autocompletion
Slow autocompletion can make the command line hang. Therefore, by default, Autocomplete waits at
most 1 second for completion to finish. You can change this value as follows:
```zsh
zstyle ':autocomplete:*' timeout 2.0 # seconds (float)
```
Note, though, that increasing this value can make your command line feel less responsive.
### Wait for a minimum amount of input
To suppress autocompletion until a minimum number of characters have been typed:
```zsh
zstyle ':autocomplete:*' min-input 3
```
### Don't show completions if the current word matches a pattern
For example, this will stop completions from showing whenever the current word consists of two or
more dots:
```zsh
zstyle ':autocomplete:*' ignored-input '..##'
```
## Change the max number of lines shown
By default, Autocomplete lets the history menu fill half of the screen, and limits all real-time
listings to a maximum of 16 lines. You can change these limits as follows:
```zsh
# Note: -e lets you specify a dynamically generated value.
# Override default for all listings
# $LINES is the number of lines that fit on screen.
zstyle -e ':autocomplete:*:*' list-lines 'reply=( $(( LINES / 3 )) )'
# Override for recent path search only
zstyle ':autocomplete:recent-paths:*' list-lines 10
# Override for history search only
zstyle ':autocomplete:history-incremental-search-backward:*' list-lines 8
# Override for history menu only
zstyle ':autocomplete:history-search-backward:*' list-lines 2000
```
Note that for all real-time listings, the maximum number of lines is additionally capped to the
number of lines that fit on screen. However, there is no such limit for the history menu. If that
generates more lines than fit on screen, you can simply use PgUp and PgDn to
scroll through the excess lines. (Note: On some terminals, you have to additionally hold
Shift or, otherwise, it will scroll the terminal buffer instead.)
### Use a custom backend for recent directories
Autocomplete comes with its own backend for keeping track of and listing recent directories (which
uses part of
[`cdr`](https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#Recent-Directories) under the
hood). However, you can override this and supply Autocomplete with recent directories from any
source that you like. To do so, define a function like this:
```sh
+autocomplete:recent-directories() {
typeset -ga reply=( )
}
```
#### Add a backend for recent files
Out of the box, Autocomplete doesn't track or offer recent files. However, it will do so if you add
a backend for it:
```sh
+autocomplete:recent-files() {
typeset -ga reply=( )
}
```
## Troubleshooting
Try the steps in the
[bug report template](.github/ISSUE_TEMPLATE/bug-report.md).
## Author & License
See the [LICENSE](LICENSE) file for details.