Skip to content

adaszko/tree_climber_rust.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

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 this plugin
nvim-treesitter tree_climber_rust

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], <A, B, C>, 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 (which you should be using if you aren't already):

vim.g.rustaceanvim = {
  server = {
    on_attach = function(client, bufnr)
      local opts = { noremap=true, silent=true }
      vim.api.nvim_buf_set_keymap(bufnr, 'n', 's', '<cmd>lua require("tree_climber_rust").init_selection()<CR>', opts)
      vim.api.nvim_buf_set_keymap(bufnr, 'x', 's', '<cmd>lua require("tree_climber_rust").select_incremental()<CR>', opts)
      vim.api.nvim_buf_set_keymap(bufnr, 'x', 'S', '<cmd>lua require("tree_climber_rust").select_previous()<CR>', 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.