Skip to content

Treesitter

Treesitter is a powerful parser generator tool and incremental parsing library that provides advanced syntax highlighting, code folding, and structural text editing capabilities.

What Problem Does It Solve?

Traditional syntax highlighting in Neovim:

  • Is regex-based and often inaccurate
  • Can be slow for large files
  • Doesn’t understand code structure
  • Lacks advanced features like intelligent code folding

How It Improves Productivity

  1. Better Syntax Highlighting:

    • More accurate highlighting
    • Faster performance
    • Better handling of complex syntax
    • Support for many languages
  2. Advanced Code Features:

    • Intelligent code folding
    • Structural text editing
    • Better code navigation
    • Improved code understanding
  3. Language Support:

    • Extensive language support
    • Easy to add new languages
    • Better handling of embedded languages
    • Consistent highlighting across languages

How to Use

Basic Usage

  • Syntax highlighting works automatically
  • Use :TSInstall <language> to install a language parser
  • Use :TSUpdate to update all parsers
  • Use :TSBufInfo to see current buffer info

Code Folding

  • Use zc to fold at current node
  • Use zo to unfold
  • Use zR to unfold all
  • Use zM to fold all
  • Use ]c to go to next class
  • Use ]f to go to next function
  • Use ]i to go to next if statement
  • Use ]p to go to next parameter

Text Objects

  • Use viw for inner word
  • Use vif for inner function
  • Use vic for inner class
  • Use via for inner argument