Nvim-Treeclimber
Neovim plugin for treesitter based navigation and selection. Takes inspiration from ParEdit.
Usage
Navigation
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
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.
Dependencies
Required
Optional
At the moment nvim-treeclimber depends on Lush to provide the default highlight groups that are based on your colorscheme. This is a temporary dependency and will be removed in the future.
If you want to use this plugin without lush manually configure the plugin, see configuration.
Configuration
To use default highlight, keymaps, and commands call require('nvim-treeclimber').setup()
.
To manually specify the configuration options edit the below snippet as desired, note that this will change in the future:
local tc = require('nvim-treeclimber')
-- Highlight groups
-- Change if you don't have Lush installed
local color = require("nvim-treeclimber.hi")
local bg = color.bg_hsluv("Normal")
local fg = color.fg_hsluv("Normal")
local dim = bg.mix(fg, 20)
vim.api.nvim_set_hl(0, "TreeClimberHighlight", { background = dim.hex })
vim.api.nvim_set_hl(0, "TreeClimberSiblingBoundary", { background = color.terminal_color_5.hex })
vim.api.nvim_set_hl(0, "TreeClimberSibling", { background = color.terminal_color_5.mix(bg, 40).hex, bold = true })
vim.api.nvim_set_hl(0, "TreeClimberParent", { background = bg.mix(fg, 2).hex })
vim.api.nvim_set_hl(0, "TreeClimberParentStart", { background = color.terminal_color_4.mix(bg, 10).hex, bold = true })
-- 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" })
vim.keymap.set(
{ "n", "x", "o" },
"<M-e>",
tc.select_forward_end,
{ desc = "select and move to the end of the node, or the end of the next node" }
)
vim.keymap.set(
{ "n", "x", "o" },
"<M-b>",
tc.select_backward,
{ desc = "select and move to the begining of the node, or the beginning of the next node" }
)
vim.keymap.set({ "n", "x", "o" }, "<M-[>", tc.select_siblings_backward, {})
vim.keymap.set({ "n", "x", "o" }, "<M-]>", tc.select_siblings_forward, {})
vim.keymap.set(
{ "n", "x", "o" },
"<M-g>",
tc.select_top_level,
{ desc = "select the top level node from the current position" }
)
vim.keymap.set({ "n", "x", "o" }, "<M-h>", tc.select_backward, { desc = "select previous node" })
vim.keymap.set({ "n", "x", "o" }, "<M-j>", tc.select_shrink, { desc = "select child node" })
vim.keymap.set({ "n", "x", "o" }, "<M-k>", tc.select_expand, { desc = "select parent node" })
vim.keymap.set({ "n", "x", "o" }, "<M-l>", tc.select_forward, { desc = "select the next node" })
vim.keymap.set({ "n", "x", "o" }, "<M-L>", tc.select_grow_forward, { desc = "Add the next node to the selection" })
vim.keymap.set({ "n", "x", "o" }, "<M-H>", tc.select_grow_backward, { desc = "Add the next node to the selection" })
Copyright Dylan Kendal 2022.