Skip to content

Commit 0e39a70

Browse files
committed
feat: remap treesitter incremental selection not to collide with mini.ai
1 parent c0cc054 commit 0e39a70

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

init.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,25 @@ require('lazy').setup({
921921
end
922922
end,
923923
})
924+
925+
-- Treesitter incremental selection, see `:help treesitter-incremental-selection`
926+
-- Note: the default keymaps `an` and `in` collide with mini.ai, so we remap them below
927+
-- Try putting your cursor in one of the lines below and typing `v+` (then continue to type `+` or `-`)
928+
vim.keymap.set({ 'x', 'o' }, '+', function()
929+
if vim.treesitter.get_parser(nil, nil, { error = false }) then
930+
require('vim.treesitter._select').select_parent(vim.v.count1)
931+
else
932+
vim.lsp.buf.selection_range(vim.v.count1)
933+
end
934+
end, { desc = 'Select parent (outer) node' })
935+
936+
vim.keymap.set({ 'x', 'o' }, '-', function()
937+
if vim.treesitter.get_parser(nil, nil, { error = false }) then
938+
require('vim.treesitter._select').select_child(vim.v.count1)
939+
else
940+
vim.lsp.buf.selection_range(-vim.v.count1)
941+
end
942+
end, { desc = 'Select child (inner) node' })
924943
end,
925944
},
926945

0 commit comments

Comments
 (0)