Neovim plugin for treesitter based navigation and selection. Takes inspiration from ParEdit.
Key binding | Action | Demo |
---|---|---|
leader-k |
Populate the quick fix with all branches required to reach the current node | :TCShowControlFlow |
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
Populate the quick fix with all branches required to reach the current node.
tc-show-control-flow.mp4
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.
Required
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
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.