Neovim 101 — Tree-sitter
The introduction of Lua and Tree-sitter provides us with endless possibilities to customize Neovim.
In this article, we will get into the basics of Tree-sitter and use the Neovim Tree-sitter APIs to develop a function navigator.
This article is part of the Neovim 101 series.
The Neovim configuration files are available in this repository.
The Tree-sitter website provides a playground that we can use to experiment with different programming languages without installing any plugins.
E.g, for Python,
Using the playground, we can experiment with the Tree-sitter query.
E.g., In the screenshot below, we use a query to highlight the Python function name
Let’s look at this simple query.
name: (identifier) @func_name
identifierindicate the node type, and they are enclosed with parentheses. In our case, the
identifiernode is within the
nameis a field. We use it to make the pattern more specific. In our case, we want to identify the function name.