Giter Club home page Giter Club logo

treesitter-unit's Introduction

treesitter-unit

A tiny Neovim plugin to deal with treesitter units. A unit is defined as a treesitter node including all its children. It allows you to quickly select, yank, delete or replace language-specific ranges.

For inner selections, the main node under the cursor is selected. For outer selections, the next node is selected.

demo-with-highlight

Installation

Requirements: nvim-treesitter including a parser for your language

For vim-plug:

Plug 'David-Kunz/treesitter-unit'

For packer:

use 'David-Kunz/treesitter-unit'

Usage

Select treesitter unit

You can select the current treesitter unit

:lua require"treesitter-unit".select(outer?)

This function takes an optional Boolean flag to specify if the outer scope should be selected as well, default false. For operations like delete, change, ... please see section "Useful mappings".

Automatic Highlighting

You can toggle automatic highlighting for the current treesitter unit.

:lua require"treesitter-unit".toggle_highlighting(higroup?)

As an optional parameter you can specify the highlight group, default: "CursorLine".

Alternative: enable_highlighting(higroup?) and disable_highlighting().

Useful mappings

For init.vim:

xnoremap iu :lua require"treesitter-unit".select()<CR>
xnoremap au :lua require"treesitter-unit".select(true)<CR>
onoremap iu :<c-u>lua require"treesitter-unit".select()<CR>
onoremap au :<c-u>lua require"treesitter-unit".select(true)<CR>

For init.lua:

vim.api.nvim_set_keymap('x', 'iu', ':lua require"treesitter-unit".select()<CR>', {noremap=true})
vim.api.nvim_set_keymap('x', 'au', ':lua require"treesitter-unit".select(true)<CR>', {noremap=true})
vim.api.nvim_set_keymap('o', 'iu', ':<c-u>lua require"treesitter-unit".select()<CR>', {noremap=true})
vim.api.nvim_set_keymap('o', 'au', ':<c-u>lua require"treesitter-unit".select(true)<CR>', {noremap=true})

Examples:

  • viu to select the inner unit
  • cau to change the outer unit

Similar plugins

Making-of video

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.