Treewalker uses neovim’s native Treesitter under the hood for syntax tree awareness.
It has no dependencies, and is meant to “just work”. It’s “batteries included”, with minimal configuration.
The movement commands move you through the syntax tree in an intuitive way:
:Treewalker Up
– Moves up to the previous neighbor node, skipping comments, annotations, and other unintuitive nodes:Treewalker Down
– Moves down to the next neighbor node, skipping comments, annotations, and other unintuitive nodes:Treewalker Left
– Moves to the first ancestor node that’s on a different line from the current node:Treewalker Right
– Moves to the next node down that’s indented further than the current node
All movement commands add to the jumplist
, so if you use a movement command
and then feel lost, you always have Ctrl-o
available to bring you back to where you last were.
Swap{Up,Down}
operate on a linewise basis, and bring along their comments, decorators, and annotations.
These are meant for swapping declarations and definitions – things that take up whole lines.
Swap{Left,Right}
are meant for swapping function arguments, enum members, list elements, etc. Things that are many per line.
In some cases these will operate on the same nodes as Up/Down, but won’t take the accoutrements.
:Treewalker SwapUp
– Swaps the highest node on the line upwards in the document:Treewalker SwapDown
– Swaps the biggest node on the line downward in the document:Treewalker SwapLeft
– Swap the node under the cursor with its previous neighbor:Treewalker SwapRight
– Swap the node under the cursor with its next neighbor
{ 'aaronik/treewalker.nvim', -- The following options are the defaults. -- Treewalker aims for sane defaults, so these are each individually optional, -- and setup() does not need to be called, so the whole opts block is optional as well. opts = { -- Whether to briefly highlight the node after jumping to it highlight = true, -- How long should above highlight last (in ms) highlight_duration = 250, -- The color of the above highlight. Must be a valid vim highlight group. -- (see :h highlight-group for options) highlight_group = 'CursorLine', } }
use { 'aaronik/treewalker.nvim', -- The setup function is optional, defaults are meant to be sane -- and setup does not need to be called setup = function() require('treewalker').setup({ -- Whether to briefly highlight the node after jumping to it highlight = true, -- How long should above highlight last (in ms) highlight_duration = 250, -- The color of the above highlight. Must be a valid vim highlight group. -- (see :h highlight-group for options) highlight_group = 'CursorLine', }) end }
Plug 'aaronik/treewalker.nvim' " This line is optional :lua require('treewalker').setup({ highlight = true, highlight_duration = 250, highlight_group = 'CursorLine' })
I’ve found Ctrl – h / j / k / l to be a really natural flow for this plugin, and adding
Shift to that for swapping just felt so clean. So here are the mappings I use:
In init.lua
: