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

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.

Listo para agents

Instalación con revisión previa

Este activo requiere revisión. El prompt copiado pide dry-run, muestra escrituras y continúa solo tras confirmación.

Needs Confirmation · 66/100Política: confirmar
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
nvim-treesitter
Comando con revisión previa
npx -y tokrepo@latest install d358e1a0-8a1b-11f1-9bc6-00163e2b0d79 --target codex

Primero dry-run, confirma las escrituras y luego ejecuta este comando.

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

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