zsh-autosuggestions
Fish-like autosuggestions based on command history.
Official WebsiteFeatures
Installation
brew install zsh-autosuggestionspacman -S zsh-autosuggestionsWhy use zsh-autosuggestions?
Faster input
Automatically suggests commands you've typed before. Complete long commands with just a few keystrokes.
History-based suggestions
Suggests optimal candidates from command history. Frequently used commands are prioritized.
Typo prevention
Correct commands are suggested, reducing typos and supporting accurate command entry.
Seamless integration
Easy integration with Oh My Zsh and other Zsh frameworks. Simple configuration.
Installation
You can install it using multiple methods. Choose based on your environment.
Homebrew (macOS / Linux)
# Install with Homebrew
brew install zsh-autosuggestions
# Add to ~/.zshrc
source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zshAs an Oh My Zsh plugin
# Clone the repository
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# Add to plugins in ~/.zshrc
plugins=(
git
zsh-autosuggestions
# other plugins...
)APT (Debian / Ubuntu)
# Install the package
sudo apt install zsh-autosuggestions
# Add to ~/.zshrc
source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zshManual installation
# Clone the repository
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
# Add to ~/.zshrc
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zshShell Configuration
Basic configuration is just loading with the source command. Edit ~/.zshrc to add settings.
Basic configuration
# ~/.zshrc
# Load zsh-autosuggestions
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
# Or if using Oh My Zsh
plugins=(git zsh-autosuggestions)Usage
As you start typing a command, suggestions automatically appear in gray text.
Basic usage example
Keybindings
| Key | Action |
|---|---|
→ or End | Accept the entire suggestion |
Ctrl + → | Accept up to the next word in the suggestion |
Alt + → | Accept up to the next word in the suggestion (alternative) |
Operation flow example
Customization
You can customize behavior by setting environment variables.
Change suggestion color
# ~/.zshrc
# Change suggestion display color (default is fg=8 = gray)
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#666666"
# Other style examples
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=cyan"
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=magenta,bold"
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff00ff,bg=cyan,bold,underline"Configure completion strategy
# ~/.zshrc
# Completion strategy (default: history)
# Multiple can be specified, used in priority from left
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
# Available strategies:
# - history: Get suggestions from command history
# - completion: Get suggestions from Zsh completion system
# - match_prev_cmd: Get suggestions from history based on previous commandCustomize keybindings
# ~/.zshrc
# Change key to accept suggestion
bindkey '^ ' autosuggest-accept # Accept with Ctrl+Space
# Accept partially
bindkey '^[[1;5C' forward-word # Accept word by word with Ctrl+→
# Accept without executing (editable)
bindkey '^E' autosuggest-acceptConfigure buffer size
# ~/.zshrc
# Minimum input characters to enable completion (default: 0)
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
# Enable async mode (useful with large history)
ZSH_AUTOSUGGEST_USE_ASYNC=1Display examples
Real-world operation examples.
Long command completion
Just press → to complete the long command
Path completion
Remembers directories you've visited before
Git command completion
Tips
Clean up history
Too many unnecessary commands in history make proper suggestions harder to find.
# Exclude specific commands from history
setopt HIST_IGNORE_SPACE # Exclude commands starting with space
setopt HIST_IGNORE_DUPS # Exclude duplicate commands
setopt HIST_FIND_NO_DUPS # Exclude duplicates in history search
# Remove specific patterns from history
fc -W # Write history to file
# After editing ~/.zsh_history
fc -R # Reload historyUse with zsh-syntax-highlighting
When using with zsh-syntax-highlighting, load zsh-autosuggestions first. This ensures syntax highlighting is applied correctly to suggestion text.
# Load order in ~/.zshrc
plugins=(
git
zsh-autosuggestions # Load first
zsh-syntax-highlighting # Load last
)Slow completion
Completion can be slow with large history. Enable async mode.
# ~/.zshrc
# Enable async mode
ZSH_AUTOSUGGEST_USE_ASYNC=1
# Set appropriate history size
HISTSIZE=10000
SAVEHIST=10000Temporarily disable completion
If autocompletion gets in the way in certain situations, you can disable it temporarily.
# Temporarily disable
unset ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE
# Or disable for specific widgets
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-search-backward)Related Articles
zsh-syntax-highlighting - Command Highlighting
Fish-like syntax highlighting for Zsh
Zsh - Z Shell
Modern shell with powerful customization and plugin ecosystem
Fish - Friendly Interactive Shell
User-friendly shell with syntax highlighting and autosuggestions out of the box