Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/adaszko/tree_climber_rust.nvim

Neovim incremental selection tailored for Rust
https://github.com/adaszko/tree_climber_rust.nvim

neovim neovim-plugin nvim nvim-plugin tree-sitter treesitter

Last synced: 6 days ago
JSON representation

Neovim incremental selection tailored for Rust

Awesome Lists containing this project

README

        

Implements specialized logic for visual-selecting Rust code syntax tree nodes stopping by at more places than
any language-agnostic plugin can. Why would want to do that? It speeds up frequent editing scenarios by
requiring fewer steps to select the interesting bits. It lifts your editing routines up a semantic level from
"visually select this word and the trailing comma" to "visually select this function argument".

[nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter#incremental-selection) | this plugin
:--------------:|:-------------------------:
![nvim-treesitter](https://raw.githubusercontent.com/adaszko/tree_climber_rust.nvim/demo/demo/treesitter.gif) | ![tree_climber_rust](https://raw.githubusercontent.com/adaszko/tree_climber_rust.nvim/demo/demo/tree_climber_rust.gif)

The demo illustrates selecting a tuple element but that's not all the pluging offers. Analogous selection
behavior also works for any comma-separated syntax element, e.g. `vec![1, 2, 3]`, ``, `f(1, 2, 3)`,
function parameters, etc.

# Setup

Instruct your favorite Neovim package manager to clone `adaszko/tree_climber_rust.nvim` from GitHub and then
hook it up to [rustaceanvim](https://github.com/mrcjkb/rustaceanvim) (which you should be using if you aren't
already):

```lua
vim.g.rustaceanvim = {
server = {
on_attach = function(client, bufnr)
local opts = { noremap=true, silent=true }
vim.api.nvim_buf_set_keymap(bufnr, 'n', 's', 'lua require("tree_climber_rust").init_selection()', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'x', 's', 'lua require("tree_climber_rust").select_incremental()', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'x', 'S', 'lua require("tree_climber_rust").select_previous()', opts)
end,
},
}
```

# Prior work

All of these below work well but do more coarse-grained jumps due to being language-agnostic and relying on
tree-sitter grammars to define jump points.

* [tree-sitter's builtin incremental selection](https://github.com/nvim-treesitter/nvim-treesitter#incremental-selection)

* [syntax-tree-surfer](https://github.com/ziontee113/syntax-tree-surfer) implements walking the syntax tree
in all directions whereas this pluging only does walking upwards to keep cognitive load low while
maximizing utility at the same time

* [Helix's builtin `expand_selection`, `shrink_selection`, `select_prev_sibling`, `select_next_sibling`](https://docs.helix-editor.com/keymap.html)
* Demo: [Navigating the syntax tree with helix](https://www.youtube.com/watch?v=8BikrCguI6M)

* An alternative way to achieve similarish effects would be to define custom text objects via
[nvim-treesitter-textobjects](https://github.com/nvim-treesitter/nvim-treesitter-textobjects#text-objects-select)
custom [treesitter
queries](https://github.com/nvim-treesitter/nvim-treesitter-textobjects/blob/23b820146956b3b681c19e10d3a8bc0cbd9a1d4c/queries/rust/textobjects.scm).