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
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
{
"BibekBhusal0/tree-hierarchy.nvim",
dependencies = { "nvim-treesitter/nvim-treesitter" },
config = function()
require("tree-hierarchy").setup({})
end,
}
| 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 |
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
})
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
This is a new plugin, if you want new features or find any bugs feel free to open Issues and Pull Requests.
[!NOTE] Some similar plugins may not support the latest Treesitter API in latest main branch.