Giter Site home page Giter Site logo

nvim-treesitter-sexp's Introduction

nvim-treesitter-sexp

A plugin for Neovim for editing code by manipulating the Treesitter AST. Basically a reimplementation of vim-sexp using treesitter queries. This is particularly useful for editing Lisps and manipulating data structures

Requirements

  • Neovim 0.9.1 or later
  • nvim-treesitter with the relevant language parsers installed

Configuration

Calling setup is not required to use nvim-treesitter-sexp, it is only needed for configuration

Example with default config values:

require("treesitter-sexp").setup {
  -- Enable/disable
  enabled = true,
  -- Move cursor when applying commands
  set_cursor = true,
  -- Set to false to disable all keymaps
  keymaps = {
    -- Set to false to disable keymap type
    commands = {
      -- Set to false to disable individual keymaps
      swap_prev_elem = "<e",
      swap_next_elem = ">e",
      swap_prev_form = "<f",
      swap_next_form = ">f",
      promote_elem = "<LocalLeader>O",
      promote_form = "<LocalLeader>o",
      splice = "<LocalLeader>@",
      slurp_left = "<(",
      slurp_right = ">)",
      barf_left = ">(",
      barf_right = "<)",
      insert_head = "<I",
      insert_tail = ">I",
    },
    motions = {
      form_start = "(",
      form_end = ")",
      prev_elem = "[e",
      next_elem = "]e",
      prev_elem_end = "[E",
      next_elem_end = "]E",
      prev_top_level = "[[",
      next_top_level = "]]",
    },
    textobjects = {
      inner_elem = "ie",
      outer_elem = "ae",
      inner_form = "if",
      outer_form = "af",
      inner_top_level = "iF",
      outer_top_level = "aF",
    },
  },
}

Commands

The commands can be called using :TSSexp with any of the following arguments:

swap_prev_elem, swap_next_elem, swap_prev_form, swap_next_form, promote_elem, promote_form, splice, slurp_left, slurp_right, barf_left, barf_right

Mappings

The default mappings are taken from vim-sexp and vim-sexp-mappings-for-regular-people. I've avoided any use of the meta key

Supported languages

For nvim-treesitter-sexp to support a language requires a query file. I'm open to adding more queries and welcome contributions to support more languages.

  • clojure
  • fennel
  • janet
  • query tree-sitter query language

nvim-treesitter-sexp's People

Contributors

leafgarland avatar paterjason avatar practicalli-johnny avatar tylerw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nvim-treesitter-sexp's Issues

Add vimdoc

Only documentation is currently the readme. It would be good to add helpfiles. Maybe explore options to generate documentation from lua annotations

[FR] Wrap element/form

Hi, and thanks for a beautiful plugin! Learning Clojure these days, and this is a huge help in my editing experience...

I was wondering if it would be possible to implement a wrapping function, similar to the one used in vim-sexp?

nvim-treesitter breaking change - rename `has-type` to `kind-eq` to align with Helix

nvim-treesitter has a breaking change that renames has-type to kind-eq to align with Helix

nvim-treesitter/nvim-treesitter@a80fe08

Updating nvim-treesitter with this commit breaks nvim-treesitter-sexp commands.

Example error:

E5108: Error executing lua ...4-0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:763: No handler for has-type?
stack traceback:
	[C]: in function 'error'
	...4-0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:763: in function 'match_preds'
	...4-0.10.0/share/nvim/runtime/lua/vim/treesitter/query.lua:963: in function '(for generator)'
	.../lazy/nvim-treesitter-sexp/lua/treesitter-sexp/utils.lua:68: in function 'get_forms'
	.../lazy/nvim-treesitter-sexp/lua/treesitter-sexp/utils.lua:192: in function 'get_form'
	...zy/nvim-treesitter-sexp/lua/treesitter-sexp/commands.lua:107: in function <...zy/nvim-treesitter-sexp/lua/treesitter-sexp/commands.lua:106>

Tested with AstroNvim 4 using lazy package manger

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.