Neovim 101 —Tree-sitter Usage

Practical usage of Neovim Tree-sitter.

alpha2phi
5 min readSep 17, 2022

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.

Getting Started

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.

Swapping

Previously we use the nvim-treesitter-textobjects plugin to swap parameters. Let’s extend this feature to other text objects.

In the 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)

--

--

alpha2phi
alpha2phi

Written by alpha2phi

Software engineer, Data Science and ML practitioner.

No responses yet