nvim-treeclimber
nvim-treeclimber copied to clipboard
Neovim structured editing plugin
Nvim-Treeclimber
Neovim plugin for treesitter based navigation and selection. Takes inspiration from ParEdit.
Requires neovim >= 0.10.
Usage
Navigation
Key binding | Action | Demo |
---|---|---|
alt-h |
Select the previous sibling node. | ![]() |
alt-j |
Shrink selection. The video also shows growing the selection first. Shrinking selects a child node from the current node, or will undo the action of a previous expand operation. | ![]() |
alt-k |
Expand selection by selecting the parent of the current node or node under the cursor. | ![]() |
alt-l |
Select the next sibling node. | ![]() |
alt-shift-l |
Add the next sibling to the selection. | ![]() |
alt-shift-h |
Add the previous sibling to the selection. | ![]() |
alt-[ |
Select the first sibling relative to the current node. | ![]() |
alt-] |
Select the last sibling relative to the current node . | ![]() |
alt-g |
Select the top level node relative to the cursor or selection. | ![]() |
Inspection
Key binding | Action | Demo |
---|---|---|
leader-k |
Populate the quick fix with all branches required to reach the current node | :TCShowControlFlow |
Commands
:TCDiffThis
Diff two visual selections based on their AST difference. Requires that difft is available in your path.
To use, make your first selection and call :TCDiffThis
, then make your second selection and call :TCDiffThis
again.
:TCShowControlFlow
Populate the quick fix with all branches required to reach the current node.
https://user-images.githubusercontent.com/3162299/203097777-a9a84c2d-8dec-4db8-a4c7-4c9a66ca26fe.mp4
Installation
Use your preferred package manager, or the built-in package system (:help packages
).
mkdir -p ~/.config/nvim/pack/dkendal/opt
cd ~/.config/nvim/pack/dkendal/opt
git clone https://github.com/dkendal/nvim-treeclimber.git
-- ~/.config/nvim/init.lua
vim.cmd.packadd('nvim-treeclimber')
require('nvim-treeclimber').setup()
If you want to change the default keybindings, call require('nvim-treeclimber')
rather than calling setup.
See configuration.
Configuration
To use default highlight, keymaps, and commands call require('nvim-treeclimber').setup()
.
To manually specify the configuration options, take a look at the contents of lua/nvim-treeclimber.lua
and import or modify the portions that you need.
For example, if you just want the built in user commands and highlights but you want your own keybindings, you can do the following:
local tc = require('nvim-treeclimber')
tc.setup_augroups()
tc.setup_user_commands()
-- Copied from setup_keymaps
vim.keymap.set("n", "<leader>k", tc.show_control_flow, {})
vim.keymap.set({ "x", "o" }, "i.", tc.select_current_node, { desc = "select current node" })
vim.keymap.set({ "x", "o" }, "a.", tc.select_expand, { desc = "select parent node" })
...
Copyright Dylan Kendal 2022.