Terminal GuideTerminal Guide
zsh-syntax-highlighting icon

zsh-syntax-highlighting

Shell Enhancements
macOSLinux
Shell

Fish-like syntax highlighting for Zsh.

Official Website

Features

Command HighlightingPath HighlightingError Detection

Installation

Homebrew
brew install zsh-syntax-highlighting
Pacman (Arch)
pacman -S zsh-syntax-highlighting

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

Homebrew
# 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.zsh

As an Oh My Zsh plugin

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

APT
# Install the package
sudo apt install zsh-syntax-highlighting

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

Manual installation

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

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

# Other plugins and settings...

# Load zsh-syntax-highlighting last
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

Highlight examples

Colors change in real-time based on command input.

Valid commands (green)

ls -la ~/Documents
git status
docker ps -a

Existing commands are displayed in green

Invalid commands (red)

lss -la # Typo in ls
gti status # Typo in git
nonexistent-command

Non-existent commands are warned in red

Path highlighting

cat ~/.zshrc # Existing file (underlined)
cd ~/nonexistent # Non-existent path

Quotes and variables

echo "Hello, $USER"
echo 'Single quotes: $USER' # Variables not expanded in single quotes

Pipes and redirects

cat file.txt | grep "pattern"
echo "hello" > output.txt
cat < input.txt

Default color meanings

Valid command
Invalid command
Option/argument
Quote/path
Pipe/redirect
Variable

Customization

You can customize highlight colors and styles. Configure before sourcing.

Change highlight color

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

Select highlighter

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

Bracket highlighting configuration

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

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

Use 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.

~/.zshrc
plugins=(
  git
  zsh-autosuggestions      # First
  zsh-syntax-highlighting  # Last
)

Warn about dangerous commands

Use pattern highlighting to make dangerous commands stand out.

Warn about dangerous commands
# ~/.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.

~/.zshrc
# Limit maximum characters to highlight (default: no limit)
ZSH_HIGHLIGHT_MAXLENGTH=512

Available style attributes

Attributes available for highlight styles.

fg=COLORbg=COLORboldunderlinestandoutnone

COLOR: black, red, green, yellow, blue, magenta, cyan, white, or a number from 0-255

Written by Dai AokiPublished: 2026-01-20

Related Articles

Explore More