How do I get improved syntax highlighting with Tree-sitter in Neovim?
Answer
:TSInstall language
Explanation
nvim-treesitter provides Tree-sitter integration for Neovim, offering faster and more accurate syntax highlighting, indentation, and text objects.
How it works
- Install the nvim-treesitter plugin
:TSInstall pythoninstalls the Python parser- Tree-sitter parses code into an AST for precise highlighting
- Replaces regex-based syntax highlighting
Example
require('nvim-treesitter.configs').setup {
ensure_installed = { 'python', 'javascript', 'go', 'lua' },
highlight = { enable = true },
indent = { enable = true },
}
Tips
- Requires Neovim 0.5+
:TSInstall allinstalls all parsers:TSUpdateupdates installed parsers- Tree-sitter text objects (via nvim-treesitter-textobjects) provide language-aware selection
- Significantly faster than regex-based highlighting for large files