yorickpeterse / nvim-tree-pairs

NeoVim plugin for jumping to the other end of the current Tree-sitter node
Mozilla Public License 2.0
75 stars 0 forks source link

nvim-tree-pairs

A NeoVim plugin that uses Tree-sitter to allow jumping between the matching opposing end of a Tree-sitter node, such as brackets, quotes, and more.

A recording of using the plugin

What does it do?

Why?

When using Tree-sitter, the % motion of NeoVim doesn't always work reliably, as it requires syntax information not present when using Tree-sitter. This is most notable when you're jumping between matching brackets (e.g. { and }), but there are a lot of lines in between, as in this case % might jump to some random location in the middle.

This plugin solves this issue by using Tree-sitter when enabled, falling back to the default % behaviour if Tree-sitter isn't enabled. When Tree-sitter is available, you can jump between the start and end of any Tree-sitter node. Take this Lua code for example:

example

When you place the cursor on the e in example and press %, the cursor jumps to the closing e. If you then press % again, it jumps back to the starting e.

Requirements

Installation

Add yorickpeterse/nvim-tree-pairs using your favourite package manager, then add the following somewhere to your init.lua:

require('tree-pairs').setup()

This creates a "pairs" Tree-sitter module that's enabled automatically. You can disable it (if needed) using :TSDisable pairs.

Limitations

This plugin doesn't have any language specific handling or Tree-sitter queries, meaning it can't handle jumping from e.g. the Lua then keyword to the next elseif keyword. This is by design, as the intent of this plugin is to be as simple as possible. Patches that apply language specific handling won't be accepted.

License

All source code in this repository is licensed under the Mozilla Public License version 2.0, unless stated otherwise. A copy of this license can be found in the file "LICENSE".