BibekBhusal0/tree-hierarchy.nvim

github github
syntax
stars 11
issues 0
subscribers 1
forks 0
CREATED

UPDATED


tree-hierarchy.nvim

A Neovim plugin for structural text navigation and editing using Treesitter.
Compatible with the latest Neovim Treesitter API (main/master branch).

https://github.com/user-attachments/assets/ec9d6e6c-4f08-499f-a0cf-eb518be0d329

Features

  • Select Parent/Child/Sibling: Navigate the syntax tree structurally.
  • Swap Nodes: Swap the current node with its next or previous sibling.
  • Dot Repeatable: Swapping operations in Normal mode are dot-repeatable.
  • Smart Context: Works intuitively in both Normal and Visual modes.

Prerequisites

This plugin relies on Tree-sitter parsers to understand the structure of your code. You must have treesitter plugin and the parser installed for the language you are editing.

Ensure you have installed the necessary parsers using nvim-treesitter:

:TSInstall <language>
" Example:
:TSInstall lua
:TSInstall python

Installation

Using lazy.nvim

{
  "BibekBhusal0/tree-hierarchy.nvim",
  dependencies = { "nvim-treesitter/nvim-treesitter" },
  config = function()
    require("tree-hierarchy").setup({})
  end,
}

Default Keymaps

Mode Keymap Action
Visual m Select Parent
Visual v Select Child
Both <leader>mk Swap with Previous Sibling
Both <leader>mj Swap with Next Sibling
Both <leader>sk Select Previous Sibling
Both <leader>sj Select Next Sibling

Configuration

Pass these options to the setup function:

require("tree-hierarchy").setup({
  debug = false,           -- Enable debug notifications (recommended to keep false)
  disable_keymaps = false, -- Disable default key mappings
})

Custom Keymaps

To use your own keymaps, set disable_keymaps = true in the setup function and define your own mappings using the provided user commands or Lua functions.

require("tree-hierarchy").setup({
  disable_keymaps = true,
})

local th = require("tree-hierarchy")

-- Example Custom Mappings
vim.keymap.set("x", "<CR>", th.select_parent, { desc = "Select Parent" })
vim.keymap.set("x", "<BS>", th.select_child, { desc = "Select Child" })

-- You can also use User Commands:
-- :THSelectParent
-- :THSelectChild
-- :THSelectNext
-- :THSelectPrev
-- :THSwapNext
-- :THSwapPrev

Contributing

This is a new plugin, if you want new features or find any bugs feel free to open Issues and Pull Requests.

Credits

Similar Plugins

[!NOTE] Some similar plugins may not support the latest Treesitter API in latest main branch.

License

MIT