Skip to content

shushtain/incselect.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Incselect for Neovim

Incselect lets you incrementally select tree-sitter nodes.

If you've come here in search of something that will bring back the original incremental_selection module of nvim-treesitter:master, consider treesitter-modules.nvim.

Setup

There is no setup() function, as there are no configuration options for now. Just install the plugin and set your preferred keymaps (no defaults).

vim.keymap.set("n", "<CR>", require("incselect").init)
vim.keymap.set("x", "<CR>", require("incselect").parent)
vim.keymap.set("x", "<S-CR>", require("incselect").child)
vim.keymap.set("x", "<Tab>", require("incselect").next)
vim.keymap.set("x", "<S-Tab>", require("incselect").prev)
vim.keymap.set("x", "<M-CR>", require("incselect").undo)

Mind that not all terminals support modifiers for <CR> and other keys.

Usage

All functions in this section return a boolean result, which means you could fall back to other editor capabilities when the function fails to select (no parser available, no valid node found, etc).

You could fall back to regular <CR>:

vim.keymap.set("n", "<CR>", function()
  if not require("incselect").init() then
    vim.cmd("normal! j_")
  end
end)

Or select inside WORD:

vim.keymap.set("n", "<CR>", function()
  if not require("incselect").init() then
    vim.cmd("normal! viW")
  end
end)

init()

Selects node around cursor and clears history.

parent()

If node is selected, selects its parent. Otherwise, selects node for range and clears history.

child()

If node is selected, selects its first child. Otherwise, selects node for range and clears history.

If you need a quick way to access the last child, use:

vim.keymap.set("x", "<M-BS>", function()
  if require("incselect").child() then
      require("incselect").prev()
  end
end)

next()

If node is selected, selects its next sibling. If on last sibling, selects first sibling. Otherwise, selects node for range and clears history.

prev()

If node is selected, selects its previous sibling. If on first sibling, selects last sibling. Otherwise, selects node for range and clears history.

undo()

If history has at least two nodes, selects previous node. Otherwise, keeps current selection.

Considerations

  • Needs thorough testing.
  • No goals to cover every possible use case.

About

incremental selection with tree-sitter

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages