Introduction
zsh-autosuggestions brings Fish shell-style inline command suggestions to Zsh. As you type, it displays a grayed-out completion of the most likely command from your shell history, which you can accept with the right arrow key or end-of-line widget.
What zsh-autosuggestions Does
- Displays inline suggestions based on command history as you type
- Supports multiple suggestion strategies: history, completion, match_prev_cmd
- Accepts full or partial suggestions with configurable key bindings
- Updates suggestions in real-time with each keystroke
- Integrates with Zsh completion system for context-aware suggestions
Architecture Overview
The plugin hooks into Zsh's ZLE (Zsh Line Editor) via precmd and preexec widgets. On each keypress, it queries the configured strategy (history file search by default) to find a matching prefix, then renders the suggestion as a ZLE buffer suffix with a dimmed color. Accepting the suggestion copies the suffix into the main buffer.
Self-Hosting & Configuration
- Install via Oh My Zsh, Zinit, Zplug, Antigen, or Homebrew
- Set ZSH_AUTOSUGGEST_STRATEGY=(history completion) for fallback ordering
- Configure ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE to change suggestion color
- Set ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE to skip suggestions on long lines
- Bind partial accept with bindkey for word-by-word acceptance
Key Features
- Zero-latency suggestions that never block interactive typing
- Strategy stacking: try history first, fall back to completion engine
- Async mode for expensive completion strategies without input lag
- Works seamlessly with syntax highlighting and other ZLE plugins
- Minimal resource usage with no background processes
Comparison with Similar Tools
- Fish shell — has autosuggestions built-in but requires switching shells
- zsh-autocomplete — more aggressive real-time completion menu approach
- fzf tab completion — fuzzy matching in a menu rather than inline suggestions
- Atuin — full history database with search UI, heavier than inline hints
FAQ
Q: How do I accept only part of a suggestion? A: Press Ctrl+Right arrow to accept word-by-word, or bind forward-word to your preferred key.
Q: Can suggestions come from something other than history? A: Yes, set ZSH_AUTOSUGGEST_STRATEGY=(completion) to use the Zsh completion system.
Q: Does it conflict with zsh-syntax-highlighting? A: No, they work together. Load syntax-highlighting before autosuggestions for best results.
Q: How do I change the suggestion text color? A: Set ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#808080" in your .zshrc.