Terminal GuideTerminal Guide
zsh-autosuggestions icon

zsh-autosuggestions

Shell Enhancements
macOSLinux
Shell

Fish-like autosuggestions based on command history.

Official Website

Features

History-based SuggestionsRight Arrow AcceptAsync

Installation

Homebrew
brew install zsh-autosuggestions
Pacman (Arch)
pacman -S zsh-autosuggestions

Why 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)

Homebrew
# Install with Homebrew
brew install zsh-autosuggestions

# Add to ~/.zshrc
source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh

As an Oh My Zsh plugin

Oh My Zsh
# 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)

APT
# Install the package
sudo apt install zsh-autosuggestions

# Add to ~/.zshrc
source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh

Manual installation

Manual 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.zsh

Shell Configuration

Basic configuration is just loading with the source command. Edit ~/.zshrc to add settings.

Basic configuration

~/.zshrc
# ~/.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

# Type "git" and suggestions from history appear
git commit -m "Update README"|
↑ Gray part is the autocomplete suggestion

Keybindings

KeyAction
or EndAccept 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

# 1. Type "doc"
docker-compose up -d
# 2. Accept suggestion with → key
docker-compose up -d|
# 3. Execute with Enter
Creating network "app_default" with the default driver...

Customization

You can customize behavior by setting environment variables.

Change suggestion color

~/.zshrc
# ~/.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
# ~/.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 command

Customize keybindings

~/.zshrc
# ~/.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-accept

Configure buffer size

~/.zshrc
# ~/.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=1

Display examples

Real-world operation examples.

Long command completion

kubectl get pods -n production -o wide --show-labels

Just press → to complete the long command

Path completion

cd ~/projects/my-awesome-app/src/components

Remembers directories you've visited before

Git command completion

git push origin feature/user-auth
Completion from history including branch names

Tips

Clean up history

Too many unnecessary commands in history make proper suggestions harder to find.

Manage history
# 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 history

Use with zsh-syntax-highlighting

When using with zsh-syntax-highlighting, load zsh-autosuggestions first. This ensures syntax highlighting is applied correctly to suggestion text.

~/.zshrc
# 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.

Performance improvement
# ~/.zshrc

# Enable async mode
ZSH_AUTOSUGGEST_USE_ASYNC=1

# Set appropriate history size
HISTSIZE=10000
SAVEHIST=10000

Temporarily disable completion

If autocompletion gets in the way in certain situations, you can disable it temporarily.

Disable
# Temporarily disable
unset ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE

# Or disable for specific widgets
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-search-backward)
Written by Dai AokiPublished: 2026-01-20

Related Articles

Explore More