Git Product home page Git Product logo

nvim-tree-pairs's Introduction

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?

  • If the cursor is on the start or end of a Tree-sitter node (e.g. a {), jump to the other end
  • If the cursor is somewhere in the middle of a Tree-sitter node, jump to the end of the node

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

  • NeoVim main, 0.9.5 might also work but I haven't verified this
  • nvim-treesitter

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".

nvim-tree-pairs's People

Contributors

yorickpeterse avatar araaha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.