Overview
Treesitter provides advanced syntax highlighting, indentation, and code understanding through language parsers. It builds an abstract syntax tree (AST) of your code, enabling more accurate and faster highlighting than traditional regex-based approaches. Plugin: nvim-treesitter/nvim-treesitterFeatures
- Superior syntax highlighting based on AST parsing
- Automatic indentation based on code structure
- Support for 35+ languages
- Automatic HTML/JSX tag closing
- Incremental parsing for performance
- Context-aware code understanding
Configuration
Treesitter is configured inlua/magictt/plugins/treesitter.lua:
Supported Languages
The Magictt config installs parsers for these languages:Web Development
- JavaScript (
javascript,jsx) - TypeScript (
typescript,tsx) - HTML (
html) - CSS (
css) - Svelte (
svelte) - Astro (
astro)
Data & Config
- JSON (
json) - YAML (
yaml) - GraphQL (
graphql)
Backend & Systems
- Lua (
lua) - Bash (
bash) - C (
c) - Dockerfile (
dockerfile)
Documentation
- Markdown (
markdown,markdown_inline) - Vim help (
vimdoc)
Other
- Prisma ORM (
prisma) - Vim script (
vim) - Git ignore files (
gitignore) - Treesitter queries (
query)
Features in Detail
Syntax Highlighting
Treesitter provides context-aware highlighting:Automatic Tag Closing
Withnvim-ts-autotag, HTML and JSX tags close automatically:
Smart Indentation
Treesitter-based indentation understands code structure:Usage
Treesitter works automatically once configured. No keybindings are needed - it enhances your editing experience invisibly.Check Parser Status
View installed parsers:Update Parsers
Update all installed parsers:Install Additional Parsers
Install a parser not in the config:Uninstall Parsers
Check Highlighting
See what Treesitter highlights under cursor:Tips and Tricks
Parser Installation
Parsers are installed asynchronously on first load. You might see:Better Than Regex
Traditional syntax highlighting uses regex patterns that can be:- Slow on large files
- Inaccurate with complex syntax
- Unable to understand context
Incremental Parsing
Treesitter only re-parses changed portions of your file, making it fast even in large files.Language Injection
Treesitter understands embedded languages:Auto-tag Configuration
The auto-tag feature works with:- HTML files (
.html) - JSX/TSX files (
.jsx,.tsx) - Vue files (
.vue) - Svelte files (
.svelte)
Folding with Treesitter
The config sets up Treesitter-based folding:Performance
Lazy Loading
The config setslazy = false to load Treesitter immediately. This ensures:
- Syntax highlighting works from the first character
- No delay when opening files
- Consistent experience across all buffers
File Type Autocmd
Treesitter features are enabled per filetype, so only loaded when needed:Troubleshooting
Highlighting Looks Wrong
-
Check if parser is installed:
-
Update parsers:
-
Check for conflicts:
Parser Installation Fails
Missing compiler:- Parsers are downloaded from GitHub
- Check internet connection
- Try manual installation:
:TSInstall <language>
Auto-tag Not Working
Verify the file type is supported:html, javascript, javascriptreact, typescript, typescriptreact, vue, svelte
Slow Performance
- Treesitter is generally fast, but very large files (>10k lines) can be slow
- Try disabling for specific large files:
:TSBufDisable highlight - Re-enable with:
:TSBufEnable highlight
Indent Issues
If indentation seems wrong:-
Check indent expression:
-
Temporarily use default:
- Report issue if it’s a parser bug
Advanced Configuration
Add More Languages
Edittreesitter.lua to add parsers:
Disable for Specific Files
Create an autocommand:Custom Highlight Groups
Treesitter uses standard highlight groups. Customize in your theme:Dependencies
- nvim-ts-autotag - Automatic HTML/JSX tag closing
- C compiler - Required for compiling parsers (gcc, clang)
- git - For downloading parsers from repositories
Related Plugins
- LSP Setup - Code intelligence and completion
- Color schemes utilize Treesitter highlighting
Resources
- Treesitter Playground - Visualize syntax trees
- Available Parsers - Full list
- Treesitter Docs - Official documentation