Neovim 101 —Tree-sitter Usage
Previously, we went through the basics of Tree-sitter. In this article, let’s go through Tree-sitter usage to help us in coding.
This article is part of the Neovim 101 series.
The Neovim configuration files are available in this repository.
We already went through some of the practical usages of Tree-sitter in the Neovim Tips for a Betting Coding Experience series. This article covers additional tips not mentioned in the series.
lua/config/treesitter.lua file, we add the following code.
- We define the key mappings to swap different text objects (line 1 — line 15)
- We configure the swap mappings (line 25 — line 29)
Now we can swap classes.
<Alt-n><Alt-c>to swap with the next class
<Alt-p><Alt-c>to swap with the previous class
We can swap functions
<Alt-n><Alt-f>to swap with the next function
<Alt-p><Alt-f>to swap with the previous function
We can swap parameters
<Alt-n><Alt-p>to swap with the next parameter
<Alt-p><Alt-p>to swap with the previous parameter