Show HN: The Neovim syntax tree traversal plugin you've been waiting for

github.com

3 points by Aaronik 8 hours ago

Treewalker.nvim

For a while I'd been wanting a good syntax tree traversal and manipulation plugin for neovim. I tried stuff like treesitter-textobjects and syntax-tree-surfer but neither could meet my needs.

So I built the one I'd been wanting.

Introducing Treewalker.nvim (https://github.com/aaronik/treewalker.nvim). It offers movement and swapping. Design goals include stability and ergonomics.

Movement

* Up/down go to neighbor nodes up/down in the document.

* Left goes to the parent node

* Right goes to next found indent in the document

Each has their own spin on a literal tree movement. The ultimate goel is to make the movement feel ergonomic, not to strictly adhere to the AST.

Swapping

* Up/down swaps take the highest node on the line _and its comments, decorators, and annotations_. This makes it easy to swap things like route handlers. These swaps operate on whole lines.

* Left/right swaps operate on the node under the cursor. This is good for swapping arguments and list items.

The plugin aims to be stable - it's well tested and leverages types with luacheck in the CI. There are few options. It's meant to "just work".

Ok that's all, I hope this can be of some use to folks!