Incselect lets you incrementally select tree-sitter nodes.
If you've come here in search of something that will bring back the original
incremental_selectionmodule of nvim-treesitter:master, consider treesitter-modules.nvim.
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.
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)Selects node around cursor and clears history.
If node is selected, selects its parent. Otherwise, selects node for range and clears history.
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)If node is selected, selects its next sibling. If on last sibling, selects first sibling. Otherwise, selects node for range and clears history.
If node is selected, selects its previous sibling. If on first sibling, selects last sibling. Otherwise, selects node for range and clears history.
If history has at least two nodes, selects previous node. Otherwise, keeps current selection.
- Needs thorough testing.
- No goals to cover every possible use case.