Treewalker is a plugin that gives you the ability to move around your code in a syntax tree aware manner. It uses Treesitter under the hood for syntax tree awareness. It offers four subcommands: Up, Down, Right, and Left. Each command moves through the syntax tree in an intuitive way.
- Up/Down - Moves up or down to the next neighbor node
- Right - Finds the next good child node
- Left - Finds the next good parent node
Moving slowly, showing each command
{
"aaronik/treewalker.nvim",
opts = {
highlight = true -- Whether to briefly highlight the node after jumping to it
}
}
This is how I have mine mapped; in init.lua
:
vim.api.nvim_set_keymap('n', '<C-j>', ':Treewalker Down<CR>', { noremap = true })
vim.api.nvim_set_keymap('n', '<C-k>', ':Treewalker Up<CR>', { noremap = true })
vim.api.nvim_set_keymap('n', '<C-h>', ':Treewalker Left<CR>', { noremap = true })
vim.api.nvim_set_keymap('n', '<C-l>', ':Treewalker Right<CR>', { noremap = true })