Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsMay 17, 2026·3 min de lecture

zsh-syntax-highlighting — Fish-Style Syntax Highlighting for Zsh

A Zsh plugin that provides real-time syntax highlighting of commands as you type, coloring valid commands green and errors red before execution.

Prêt pour agents

Cet actif peut être lu et installé directement par les agents

TokRepo expose une commande CLI universelle, un contrat d'installation, le metadata JSON, un plan selon l'adaptateur et le contenu raw pour aider les agents à juger l'adaptation, le risque et les prochaines actions.

Needs Confirmation · 66/100Policy : confirmer
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
zsh-syntax-highlighting Overview
Commande CLI universelle
npx tokrepo install 8019b3c2-51eb-11f1-9bc6-00163e2b0d79

Introduction

zsh-syntax-highlighting colors your command line input in real-time as you type. Valid commands appear green, unknown commands red, strings are quoted in a distinct color, and paths that exist on disk get underlined. This immediate visual feedback catches typos before pressing Enter.

What zsh-syntax-highlighting Does

  • Colors recognized commands, builtins, aliases, and functions in green
  • Highlights unknown or misspelled commands in red as a visual error
  • Applies distinct colors to strings, globbing patterns, and variables
  • Underlines valid file paths and dims comments
  • Updates highlighting character by character as you type

Architecture Overview

The plugin hooks into ZLE (Zsh Line Editor) via the zle-line-pre-redraw widget. On each buffer change, it tokenizes the current command line using Zsh's own lexer, classifies each token (command, argument, path, option), checks command existence via the hash table, then applies region_highlight entries to color each span.

Self-Hosting & Configuration

  • Install via Oh My Zsh, Zinit, Zplug, Antigen, or Homebrew
  • Must be sourced at the end of .zshrc (after completions and other plugins)
  • Customize colors via ZSH_HIGHLIGHT_STYLES associative array
  • Enable additional highlighters: brackets, pattern, cursor, line
  • Pattern highlighter allows custom rules: highlight rm -rf in red

Key Features

  • Main highlighter covers commands, arguments, paths, and redirections
  • Brackets highlighter matches and colors paired parentheses and braces
  • Pattern highlighter lets you define regex-based custom highlight rules
  • Works with any color-capable terminal (256-color and truecolor)
  • Minimal overhead: highlighting completes within the ZLE redraw cycle

Comparison with Similar Tools

  • Fish shell — syntax highlighting built-in, but requires switching shells
  • fast-syntax-highlighting — community fork with async and more token types
  • zsh-autocomplete — focuses on completions rather than input coloring
  • Syntax highlighting in Bash — no equivalent exists for Bash natively

FAQ

Q: Why must this plugin be sourced last in .zshrc? A: It wraps ZLE widgets. If other plugins modify widgets after it loads, highlighting may not trigger correctly.

Q: How do I change the color of valid commands? A: Add ZSH_HIGHLIGHT_STYLES[command]='fg=cyan,bold' to .zshrc before sourcing the plugin.

Q: Does it slow down typing in large prompts? A: No, tokenization is incremental and completes in microseconds for typical command lengths.

Q: Can I highlight dangerous commands like rm -rf differently? A: Yes, enable the pattern highlighter and add: ZSH_HIGHLIGHT_PATTERNS+=('rm -rf *' 'fg=white,bold,bg=red')

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires