mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-21 12:50:09 -04:00
parent
a0dc6c8635
commit
507527711f
3 changed files with 26 additions and 22 deletions
|
|
@ -366,7 +366,7 @@ require'nvim-treesitter.configs'.setup {
|
||||||
incremental_selection = {
|
incremental_selection = {
|
||||||
enable = true,
|
enable = true,
|
||||||
keymaps = {
|
keymaps = {
|
||||||
init_selection = "gnn",
|
init_selection = "gnn", -- set to `false` to disable one of the mappings
|
||||||
node_incremental = "grn",
|
node_incremental = "grn",
|
||||||
scope_incremental = "grc",
|
scope_incremental = "grc",
|
||||||
node_decremental = "grm",
|
node_decremental = "grm",
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ local builtin_modules = {
|
||||||
module_path = "nvim-treesitter.incremental_selection",
|
module_path = "nvim-treesitter.incremental_selection",
|
||||||
enable = false,
|
enable = false,
|
||||||
keymaps = {
|
keymaps = {
|
||||||
init_selection = "gnn",
|
init_selection = "gnn", -- set to `false` to disable one of the mappings
|
||||||
node_incremental = "grn",
|
node_incremental = "grn",
|
||||||
scope_incremental = "grc",
|
scope_incremental = "grc",
|
||||||
node_decremental = "grm",
|
node_decremental = "grm",
|
||||||
|
|
|
||||||
|
|
@ -130,33 +130,37 @@ local FUNCTION_DESCRIPTIONS = {
|
||||||
function M.attach(bufnr)
|
function M.attach(bufnr)
|
||||||
local config = configs.get_module "incremental_selection"
|
local config = configs.get_module "incremental_selection"
|
||||||
for funcname, mapping in pairs(config.keymaps) do
|
for funcname, mapping in pairs(config.keymaps) do
|
||||||
local mode
|
if mapping then
|
||||||
local rhs
|
local mode
|
||||||
if funcname == "init_selection" then
|
local rhs
|
||||||
mode = "n"
|
if funcname == "init_selection" then
|
||||||
rhs = M[funcname]
|
mode = "n"
|
||||||
else
|
rhs = M[funcname]
|
||||||
mode = "x"
|
else
|
||||||
-- We need to move to command mode to access marks '< (visual area start) and '> (visual area end) which are not
|
mode = "x"
|
||||||
-- properly accessible in visual mode.
|
-- We need to move to command mode to access marks '< (visual area start) and '> (visual area end) which are not
|
||||||
rhs = string.format(":lua require'nvim-treesitter.incremental_selection'.%s()<CR>", funcname)
|
-- properly accessible in visual mode.
|
||||||
|
rhs = string.format(":lua require'nvim-treesitter.incremental_selection'.%s()<CR>", funcname)
|
||||||
|
end
|
||||||
|
vim.keymap.set(
|
||||||
|
mode,
|
||||||
|
mapping,
|
||||||
|
rhs,
|
||||||
|
{ buffer = bufnr, silent = true, noremap = true, desc = FUNCTION_DESCRIPTIONS[funcname] }
|
||||||
|
)
|
||||||
end
|
end
|
||||||
vim.keymap.set(
|
|
||||||
mode,
|
|
||||||
mapping,
|
|
||||||
rhs,
|
|
||||||
{ buffer = bufnr, silent = true, noremap = true, desc = FUNCTION_DESCRIPTIONS[funcname] }
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.detach(bufnr)
|
function M.detach(bufnr)
|
||||||
local config = configs.get_module "incremental_selection"
|
local config = configs.get_module "incremental_selection"
|
||||||
for f, mapping in pairs(config.keymaps) do
|
for f, mapping in pairs(config.keymaps) do
|
||||||
if f == "init_selection" then
|
if mapping then
|
||||||
vim.keymap.del("n", mapping, { buffer = bufnr })
|
if f == "init_selection" then
|
||||||
else
|
vim.keymap.del("n", mapping, { buffer = bufnr })
|
||||||
vim.keymap.del("x", mapping, { buffer = bufnr })
|
else
|
||||||
|
vim.keymap.del("x", mapping, { buffer = bufnr })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue