nvim-treesitter can be configured by calling the setup() function, though it works with sensible defaults out of the box.
Requirements
Before installing nvim-treesitter, ensure you have:
Installation
With lazy.nvim
The recommended way to install nvim-treesitter with lazy.nvim is:
{
'nvim-treesitter/nvim-treesitter',
lazy = false,
build = ':TSUpdate'
}
nvim-treesitter does not support lazy-loading. Always set lazy = false.
The build = ':TSUpdate' ensures parsers are automatically updated when you update the plugin.
With vim-plug
Plug 'nvim-treesitter/nvim-treesitter'
Then run :PlugInstall and :TSUpdate.
With packer.nvim
use {
'nvim-treesitter/nvim-treesitter',
run = ':TSUpdate'
}
With native packages
git clone https://github.com/nvim-treesitter/nvim-treesitter \
~/.local/share/nvim/site/pack/nvim-treesitter/start/nvim-treesitter
Then run :TSUpdate in Neovim.
Basic Configuration
You do not need to call setup() for nvim-treesitter to work. It uses sensible defaults.
The basic setup call looks like this:
require'nvim-treesitter'.setup {
-- Configuration options go here
}
Configuration Options
Custom Install Directory
By default, parsers and queries are installed to vim.fn.stdpath('data') .. '/site'. You can change this:
require'nvim-treesitter'.setup {
-- Directory to install parsers and queries to (prepended to runtimepath)
install_dir = vim.fn.stdpath('data') .. '/site'
}
The install_dir is automatically prepended to your runtimepath to ensure parsers and queries have priority.
Complete Example
Here’s a complete configuration example:
require'nvim-treesitter'.setup {
install_dir = vim.fn.stdpath('data') .. '/treesitter',
}
-- Install parsers on startup
require('nvim-treesitter').install({ 'lua', 'python', 'javascript' })
The install() function runs asynchronously by default.
Synchronous Installation (Bootstrapping)
If you’re writing a bootstrap script and need to wait for parsers to install:
-- Install parsers and wait up to 5 minutes
require('nvim-treesitter').install({
'rust',
'javascript',
'zig'
}):wait(300000)
This is useful in automation scripts or when you need parsers installed before proceeding.
Install Directories Explained
When you configure nvim-treesitter, files are organized as follows:
install_dir/
├── parser/ # Compiled parser .so files
│ ├── lua.so
│ ├── python.so
│ └── ...
├── queries/ # Query files for each language
│ ├── lua/
│ │ ├── highlights.scm
│ │ ├── indents.scm
│ │ └── ...
│ └── python/
│ └── ...
└── parser-info/ # Metadata (revision hashes)
├── lua.revision
└── ...
Verifying Your Setup
After installation and configuration:
Check health
Run :checkhealth nvim-treesitter to verify your installation.
List installed parsers
Use :TSInstallInfo to see all available and installed parsers.
Test a parser
Open a file in a supported language and check if syntax highlighting works.
Next Steps