vimtricks.wiki Concise Vim tricks, one at a time.

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 python installs 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 all installs all parsers
  • :TSUpdate updates installed parsers
  • Tree-sitter text objects (via nvim-treesitter-textobjects) provide language-aware selection
  • Significantly faster than regex-based highlighting for large files

Next

How do you yank a single word into a named register?