-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Edit:
I previously had a problem that was part of this issue I opened, I made a typo in my config which is on me. The plugin now works correctly, however, the default keymaps could still be massaged possibly.
I was giving your plugin a shot to get increment/decremental selection on treesitter 'main' after switching from master.
To be specific in case it matters I have installed treesitter 'main' and enabled highlighting, folds, and indentation via the install instructions on their repo. I am using this treesitter-modules repo solely to get the incremental selections back.
The problem:
The default incremental_selection keymaps work as expected, however, some are in conflict with the default lsp keymaps or confusing similar:
GLOBAL DEFAULTS
*grr* *gra* *grn* *gri* *grt* *i_CTRL-S*
These GLOBAL keymaps are created unconditionally when Nvim starts:
- "grn" is mapped in Normal mode to |vim.lsp.buf.rename()|
- "gra" is mapped in Normal and Visual mode to |vim.lsp.buf.code_action()|
- "grr" is mapped in Normal mode to |vim.lsp.buf.references()|
- "gri" is mapped in Normal mode to |vim.lsp.buf.implementation()|
- "grt" is mapped in Normal mode to |vim.lsp.buf.type_definition()|
- "gO" is mapped in Normal mode to |vim.lsp.buf.document_symbol()|
- CTRL-S is mapped in Insert mode to |vim.lsp.buf.signature_help()|
init_selection = 'gnn',
node_incremental = 'grn',
scope_incremental = 'grc',
node_decremental = 'grm',
Not a big deal to do some remaps, I previously used the following for many years with no issues or conflicts:
init_selection = '<A-o>',
node_incremental = '<A-o>',
scope_incremental = '<A-s>',
node_decremental = '<A-i>',
My keymaps worked out well because starting and incrementing the selection are the same key which is convenient, this is similar to the helix editor.
Example config using lazy.nvim:
return {
{
'nvim-treesitter/nvim-treesitter',
branch = 'main',
lazy = false,
enable = true,
build = ':TSUpdate',
config = function()
require('nvim-treesitter').setup({
-- Directory to install parsers and queries to (prepended to `runtimepath` to have priority).
install_dir = vim.fn.stdpath('data') .. '/site'
})
local parsers = {
'c', --*
'lua', --*
'vim', --*
'vimdoc', --*
'query', --*
'markdown', --*
'markdown_inline', --*
'gitignore',
'bash',
'javascript',
'typescript',
'html',
'css',
'yaml',
'toml',
'rust',
'cpp',
'python',
'markdown',
'svelte',
'json',
'dockerfile'
}
-- Async install
require('nvim-treesitter').install(parsers)
-- Enable treesitter parser features on any filetype.
vim.api.nvim_create_autocmd('FileType', {
pattern = { '<filetype>' },
callback = function()
-- Highlight
vim.treesitter.start()
-- Folds
vim.wo[0][0].foldexpr = 'v:lua.vim.treesitter.foldexpr()'
vim.wo[0][0].foldmethod = 'expr'
-- Indentation
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end,
})
end,
},
{
'MeanderingProgrammer/treesitter-modules.nvim',
dependencies = { 'nvim-treesitter/nvim-treesitter' },
---@module 'treesitter-modules'
---@type ts.mod.UserConfig
opts = {
incremental_selection = {
enable = true,
-- Set disable =`false` to disable individual mapping
-- node_decremental captures both node_incremental and scope_incremental.
disable = false,
keymaps = {
init_selection = '<A-o>',
node_incremental = '<A-o>',
scope_incremental = '<A-s>',
node_decremental = '<A-i>',
},
},
},
}
}