zsh-syntax-highlighting
Fish-like syntax highlighting for Zsh.
Official WebsiteFeatures
Installation
brew install zsh-syntax-highlightingpacman -S zsh-syntax-highlightingWhy use zsh-syntax-highlighting?
Catch errors immediately
Non-existent commands and syntax errors are shown in red. Catch mistakes before pressing Enter.
Visual feedback
Commands, options, and paths are color-coded, making the command line easier to read.
Typo prevention
Immediately detects spelling mistakes in command names. Prevents executing wrong commands.
Fish shell-like
Brings Fish shell's syntax highlighting to Zsh. Keep all of Zsh's flexibility.
Installation
You can install it using multiple methods. Choose based on your environment.
Homebrew (macOS / Linux)
# Install with Homebrew
brew install zsh-syntax-highlighting
# Add to ~/.zshrc (place at end of file)
source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zshAs an Oh My Zsh plugin
# Clone the repository
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# Add to plugins in ~/.zshrc
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting # Recommended to place last
)APT (Debian / Ubuntu)
# Install the package
sudo apt install zsh-syntax-highlighting
# Add to ~/.zshrc
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zshManual installation
# Clone the repository
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.zsh/zsh-syntax-highlighting
# Add to ~/.zshrc (place at end of file)
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zshImportant: zsh-syntax-highlighting must be sourced at the end of ~/.zshrc. Place it after other plugins and custom settings.
Shell Configuration
Basically, just install and source it to get it working.
Basic configuration
# ~/.zshrc
# Other plugins and settings...
# Load zsh-syntax-highlighting last
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zshHighlight examples
Colors change in real-time based on command input.
Valid commands (green)
Existing commands are displayed in green
Invalid commands (red)
Non-existent commands are warned in red
Path highlighting
Quotes and variables
Pipes and redirects
Default color meanings
Customization
You can customize highlight colors and styles. Configure before sourcing.
Change highlight color
# ~/.zshrc (configure before sourcing)
# Valid command color
ZSH_HIGHLIGHT_STYLES[command]='fg=green,bold'
# Invalid command color
ZSH_HIGHLIGHT_STYLES[unknown-token]='fg=red,bold'
# Alias color
ZSH_HIGHLIGHT_STYLES[alias]='fg=cyan,bold'
# Built-in command color
ZSH_HIGHLIGHT_STYLES[builtin]='fg=yellow,bold'
# Function color
ZSH_HIGHLIGHT_STYLES[function]='fg=magenta,bold'
# Path color
ZSH_HIGHLIGHT_STYLES[path]='fg=yellow,underline'
# Single quotes
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]='fg=green'
# Double quotes
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]='fg=yellow'
# Finally source
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zshSelect highlighter
# ~/.zshrc
# Specify which highlighters to use
ZSH_HIGHLIGHT_HIGHLIGHTERS=(
main # Commands, arguments, etc. (default)
brackets # Bracket matching
pattern # Pattern matching
cursor # Cursor position
root # Warning for root user
)
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zshBracket highlighting configuration
# ~/.zshrc
# Color configuration for brackets highlighter
ZSH_HIGHLIGHT_STYLES[bracket-level-1]='fg=blue,bold'
ZSH_HIGHLIGHT_STYLES[bracket-level-2]='fg=green,bold'
ZSH_HIGHLIGHT_STYLES[bracket-level-3]='fg=magenta,bold'
ZSH_HIGHLIGHT_STYLES[bracket-level-4]='fg=yellow,bold'
# When matching brackets are missing
ZSH_HIGHLIGHT_STYLES[bracket-error]='fg=red,standout'Pattern highlighting
# ~/.zshrc
# Highlight specific patterns
ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red')
ZSH_HIGHLIGHT_PATTERNS+=('sudo *' 'fg=yellow,bold')
# Enable pattern highlighter
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern)Tips
Importance of load order
Always load zsh-syntax-highlighting at the end of ~/.zshrc. Loading it after other plugins ensures it recognizes all commands correctly.
# Example ~/.zshrc configuration
# 1. Environment variables
export PATH="$HOME/bin:$PATH"
# 2. Oh My Zsh configuration
source $ZSH/oh-my-zsh.sh
# 3. Aliases
alias ll="ls -la"
# 4. Other plugins (zsh-autosuggestions, etc.)
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
# 5. Finally zsh-syntax-highlighting
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zshUse with zsh-autosuggestions
When using with zsh-autosuggestions, there's a recommended load order. Load zsh-autosuggestions first and zsh-syntax-highlighting last so that autocompletion suggestions are highlighted correctly.
plugins=(
git
zsh-autosuggestions # First
zsh-syntax-highlighting # Last
)Warn about dangerous commands
Use pattern highlighting to make dangerous commands stand out.
# ~/.zshrc
# Warn about dangerous commands with red background
ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red')
ZSH_HIGHLIGHT_PATTERNS+=('rm -rf /' 'fg=white,bold,bg=red')
ZSH_HIGHLIGHT_PATTERNS+=('> /dev/sda' 'fg=white,bold,bg=red')
ZSH_HIGHLIGHT_PATTERNS+=('chmod 777 *' 'fg=black,bg=yellow')
ZSH_HIGHLIGHT_PATTERNS+=('chmod -R 777 *' 'fg=black,bg=yellow')Performance
Since zsh-syntax-highlighting calculates highlighting for each input, very long command lines may experience slight delays. This is not a problem in normal usage, but if concerned you can limit the maximum length withZSH_HIGHLIGHT_MAXLENGTH.
# Limit maximum characters to highlight (default: no limit)
ZSH_HIGHLIGHT_MAXLENGTH=512Available style attributes
Attributes available for highlight styles.
fg=COLORbg=COLORboldunderlinestandoutnoneCOLOR: black, red, green, yellow, blue, magenta, cyan, white, or a number from 0-255
Related Articles
zsh-autosuggestions - Fish-like Suggestions
Fish-like autosuggestions 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