Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aaronik/treewalker.nvim
A neovim plugin for fast navigation around the abstract syntax tree
https://github.com/aaronik/treewalker.nvim
abstract-syntax-tree navigation neovim plugin
Last synced: 2 days ago
JSON representation
A neovim plugin for fast navigation around the abstract syntax tree
- Host: GitHub
- URL: https://github.com/aaronik/treewalker.nvim
- Owner: aaronik
- License: mit
- Created: 2024-11-29T02:16:01.000Z (29 days ago)
- Default Branch: main
- Last Pushed: 2024-12-25T20:52:53.000Z (2 days ago)
- Last Synced: 2024-12-25T21:18:29.314Z (2 days ago)
- Topics: abstract-syntax-tree, navigation, neovim, plugin
- Language: Lua
- Homepage:
- Size: 2.89 MB
- Stars: 253
- Watchers: 4
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![build status](https://github.com/aaronik/treewalker.nvim/actions/workflows/test.yml/badge.svg)
# Treewalker.nvim
![A demo of moving around some code quickly using the plugin](static/fast_demo.gif)
Treewalker is a plugin that gives you the ability to **move around your code in a syntax tree aware manner**.
It uses [Treesitter](https://github.com/tree-sitter/tree-sitter) under the hood for syntax tree awareness.
It offers six subcommands: Up, Down, Right, and Left for movement, and SwapUp and SwapDown for intelligent node swapping.Each movement command moves you 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 nodeThe swap commands intelligently swap nodes, including comments and attributes/decorators.
---
Typing out the Move commands manually
Typing out the Swap commands manually
---
### Installation
##### Lazy:
```lua
{
"aaronik/treewalker.nvim",-- The following options are the defaults.
-- Treewalker aims for sane defaults, so these are each individually optional,
-- and 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 = "ColorColumn",
}
}
```#### Mapping
This is how I have mine mapped; in `init.lua`:
```lua
vim.keymap.set({ 'n', 'v' }, '', 'Treewalker Up', { noremap = true, silent = true })
vim.keymap.set({ 'n', 'v' }, '', 'Treewalker Down', { noremap = true, silent = true })
vim.keymap.set({ 'n', 'v' }, '', 'Treewalker Right', { noremap = true, silent = true })
vim.keymap.set({ 'n', 'v' }, '', 'Treewalker Left', { noremap = true, silent = true })
vim.keymap.set('n', '', 'Treewalker SwapDown', { noremap = true, silent = true })
vim.keymap.set('n', '', 'Treewalker SwapUp', { noremap = true, silent = true })
```I also utilize some
[nvim-treesitter-textobjects](https://github.com/nvim-treesitter/nvim-treesitter-textobjects?tab=readme-ov-file#text-objects-swap)
commands to get lateral swapping (that way I get all four `` maps in a natural and intuitive feeling way):```lua
vim.keymap.set('n', "", ":TSTextobjectSwapNext @parameter.inner", { noremap = true, silent = true })
vim.keymap.set('n', "", ":TSTextobjectSwapPrevious @parameter.inner", { noremap = true, silent = true })
```The above can also be accomplished with
[nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) using
[ts_utils](https://github.com/nvim-treesitter/nvim-treesitter?tab=readme-ov-file#utilities).
See [this PR](https://github.com/aaronik/treewalker.nvim/pull/10/files) for
an example of that!