Core plugins
The Treesitter setup includes three main plugins:nvim-treesitter
Core parser and highlighting engine
textobjects
Code-aware text objects and motions
context
Sticky context header showing scope
Installation
Treesitter is loaded immediately (not lazy) and automatically updates parsers:lua/plugins/treesitter.lua
The
:TSUpdate command runs automatically after installation to compile all parsers.Language support
Parsers are automatically installed for these languages:lua/plugins/treesitter.lua
Auto-installation
lua/plugins/treesitter.lua
Syntax highlighting
Treesitter highlighting is enabled with performance optimizations:lua/plugins/treesitter.lua
Text objects
Treesitter text objects allow you to operate on semantic code units like functions, classes, and arguments.Selecting text objects
| Operator | Target | Description |
|---|---|---|
af | Function (outer) | Around function including signature |
if | Function (inner) | Inside function body only |
ac | Class (outer) | Around class including declaration |
ic | Class (inner) | Inside class body |
aa | Argument (outer) | Around parameter/argument |
ia | Argument (inner) | Inside argument (value only) |
ao | Loop (outer) | Around loop statement |
io | Loop (inner) | Inside loop body |
ai | Conditional (outer) | Around if/else/switch |
ii | Conditional (inner) | Inside conditional body |
ar | Return (outer) | Around return statement |
ir | Return (inner) | Return value only |
as | Scope | Around local scope |
Usage examples
- Visual selection
- Deletion
- Yanking
vif- Select inside function bodyvac- Select around classvaa- Select around argument
Configuration
lua/plugins/treesitter.lua
Lookahead allows you to target the next text object even if your cursor isn’t directly on it.
Navigation
Jump between semantic code elements:Function navigation
| Key | Action | Description |
|---|---|---|
]f | Next function start | Jump to start of next function |
]F | Next function end | Jump to end of next function |
[f | Prev function start | Jump to start of previous function |
[F | Prev function end | Jump to end of previous function |
Class navigation
| Key | Action | Description |
|---|---|---|
]c | Next class start | Jump to start of next class |
]C | Next class end | Jump to end of next class |
[c | Prev class start | Jump to start of previous class |
[C | Prev class end | Jump to end of previous class |
Loop and conditional navigation
| Key | Action | Description |
|---|---|---|
]o | Next loop | Jump to next loop |
[o | Prev loop | Jump to previous loop |
]i | Next conditional | Jump to next if/else/switch |
[i | Prev conditional | Jump to previous conditional |
Swapping
Swap function arguments/parameters:| Key | Action | Description |
|---|---|---|
<leader>a | Swap next | Swap with next parameter |
<leader>A | Swap previous | Swap with previous parameter |
lua/plugins/treesitter.lua
Example
Treesitter context
Shows the current function/class/scope at the top of the window when scrolling:lua/plugins/treesitter.lua
Sticky header
Function/class signature stays visible while scrolling
Performance optimized
Disabled for files over 200KB
Visual separator
Clear horizontal line separates context from content
Smart activation
Only shows for scopes with 20+ lines
Context example
When scrolling inside a long function:Indentation
Treesitter-based indentation:lua/plugins/treesitter.lua
Incremental selection
Expand selection based on syntax tree:| Key | Action | Description |
|---|---|---|
<leader>ss | Init selection | Start incremental selection |
<leader>si | Increment node | Expand to parent node |
<leader>sc | Increment scope | Expand to scope |
<leader>sn | Decrement node | Shrink to child node |
lua/plugins/treesitter.lua
Example workflow
Treesitter modules
The configuration usestreesitter-modules.nvim for better module organization:
lua/plugins/treesitter.lua
Commands
:TSInstall <language>
:TSInstall <language>
Install parser for specific language:
:TSUpdate
:TSUpdate
Update all installed parsers:
:TSModuleInfo
:TSModuleInfo
Show status of all Treesitter modules:
:InspectTree
:InspectTree
Open Treesitter syntax tree inspector:Shows the parsed syntax tree for current buffer.
Toggle Treesitter
Disable/enable Treesitter highlighting:Performance tips
Large files
Automatically disabled for files over 100KB
Context
Context disabled for files over 200KB
Minimal highlighting
No additional vim regex highlighting
Selective context
Context only shows for scopes with 20+ lines
Related plugins
- nvim-ts-autotag: Auto-close HTML/JSX tags (see Editing plugins)
- nvim-ts-context-commentstring: Context-aware comments (see Editing plugins)
- Blink.cmp: Uses Treesitter for smarter completions (see Completions)