Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsMay 17, 2026·3 min de lectura

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.

Listo para agents

Este activo puede ser leído e instalado directamente por agents

TokRepo expone un comando CLI universal, contrato de instalación, metadata JSON, plan según adaptador y contenido raw para que los agents evalúen compatibilidad, riesgo y próximos pasos.

Needs Confirmation · 66/100Política: confirmar
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
zsh-syntax-highlighting Overview
Comando CLI universal
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

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados