Skip to content

Dkendal/nvim-treeclimber

Repository files navigation

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. select-prev
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. select-shrink
alt-k Expand selection by selecting the parent of the current node or node under the cursor. select-expand
alt-l Select the next sibling node. select-next
alt-shift-l Add the next sibling to the selection. grow-selection-next
alt-shift-h Add the previous sibling to the selection. grow-selection-prev
alt-[ Select the first sibling relative to the current node. select-first-sibling
alt-] Select the last sibling relative to the current node . select-last-sibling
alt-g Select the top level node relative to the cursor or selection. select-top-level

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.

tc-diff-this.webm

:TCShowControlFlow

Populate the quick fix with all branches required to reach the current node.

tc-show-control-flow.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.