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

nvim-treesitter — Treesitter Configurations and Abstraction Layer for Neovim

Provides Tree-sitter parser integration for Neovim, enabling accurate syntax highlighting, incremental selection, code folding, and indentation based on real parse trees instead of regex patterns.

Prêt pour agents

Installation avec revue préalable

Cet actif nécessite une revue. Le prompt copié demande un dry-run, affiche les écritures, puis continue seulement après confirmation.

Needs Confirmation · 66/100Policy : confirmer
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
nvim-treesitter
Commande avec revue préalable
npx -y tokrepo@latest install d358e1a0-8a1b-11f1-9bc6-00163e2b0d79 --target codex

Dry-run d'abord, confirmez les écritures, puis lancez cette commande.

Introduction

nvim-treesitter brings Tree-sitter parsing to Neovim, replacing regex-based syntax highlighting with incremental, grammar-based parsing. It provides a unified interface for installing language parsers and configuring modules like highlighting, indentation, and incremental selection across 200+ languages.

What nvim-treesitter Does

  • Installs and manages Tree-sitter language parsers for 200+ languages
  • Provides syntax highlighting based on real abstract syntax trees
  • Enables incremental selection that expands to the next syntactic node
  • Offers indentation computed from the parse tree rather than heuristics
  • Supports code folding using Tree-sitter node boundaries

Architecture Overview

nvim-treesitter acts as a configuration and abstraction layer on top of Neovim's built-in Tree-sitter integration. It ships query files (highlights.scm, indents.scm, folds.scm) for each supported language, manages parser compilation and installation via :TSInstall, and exposes a module system where each feature (highlight, indent, incremental_selection) can be independently enabled or configured.

Self-Hosting & Configuration

  • Install via any Neovim plugin manager (lazy.nvim, packer, vim-plug)
  • Run :TSUpdate after installation to compile parsers
  • Configure modules in your init.lua with require('nvim-treesitter.configs').setup({})
  • Set ensure_installed to a list of languages or "all" for automatic parser installation
  • Enable specific modules: highlight = { enable = true }, indent = { enable = true }

Key Features

  • Grammar-based highlighting that handles nested languages correctly
  • Incremental selection expanding from cursor to enclosing AST nodes
  • Automatic parser installation and updates via :TSInstall / :TSUpdate
  • Query-based text objects for selecting functions, classes, and parameters
  • Playground module for inspecting the syntax tree interactively

Comparison with Similar Tools

  • Regex-based syntax — Traditional Vim highlighting uses regex patterns that break on edge cases; nvim-treesitter uses real parsers for accuracy
  • vim-polyglot — Bundles many filetype plugins but still uses regex; nvim-treesitter provides structural parsing
  • Tree-sitter CLI — The standalone CLI parses files; nvim-treesitter integrates parsing directly into the editor
  • LSP semantic tokens — Complements treesitter by adding type-aware highlighting from the language server

FAQ

Q: Does nvim-treesitter replace LSP? A: No. Tree-sitter handles syntax-level features (highlighting, folding, text objects) while LSP provides semantic features (go-to-definition, diagnostics, rename). They work together.

Q: How do I add a language parser? A: Run :TSInstall inside Neovim. The parser is compiled locally and cached.

Q: Does it slow down Neovim? A: Tree-sitter uses incremental parsing, so only changed portions of the buffer are re-parsed. Performance is comparable to or better than regex highlighting on large files.

Q: Can I write custom queries? A: Yes. Place custom query files in after/queries// in your Neovim config directory to extend or override default queries.

Sources

Fil de discussion

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

Actifs similaires