mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-22 04:21:08 +00:00
This commit is contained in:
parent
561da43c43
commit
92a7728732
1 changed files with 29 additions and 24 deletions
|
|
@ -19,7 +19,6 @@ return {
|
||||||
TS.update(nil, { summary = true })
|
TS.update(nil, { summary = true })
|
||||||
end)
|
end)
|
||||||
end,
|
end,
|
||||||
lazy = vim.fn.argc(-1) == 0, -- load treesitter early when opening a file from the cmdline
|
|
||||||
event = { "LazyFile", "VeryLazy" },
|
event = { "LazyFile", "VeryLazy" },
|
||||||
cmd = { "TSUpdate", "TSInstall", "TSLog", "TSUninstall" },
|
cmd = { "TSUpdate", "TSInstall", "TSLog", "TSUninstall" },
|
||||||
opts_extend = { "ensure_installed" },
|
opts_extend = { "ensure_installed" },
|
||||||
|
|
@ -162,34 +161,40 @@ return {
|
||||||
end
|
end
|
||||||
TS.setup(opts)
|
TS.setup(opts)
|
||||||
|
|
||||||
|
local function attach(buf)
|
||||||
|
local ft = vim.bo[buf].filetype
|
||||||
|
if not (vim.tbl_get(opts, "move", "enable") and LazyVim.treesitter.have(ft, "textobjects")) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
---@type table<string, table<string, string>>
|
||||||
|
local moves = vim.tbl_get(opts, "move", "keys") or {}
|
||||||
|
|
||||||
|
for method, keymaps in pairs(moves) do
|
||||||
|
for key, query in pairs(keymaps) do
|
||||||
|
local desc = query:gsub("@", ""):gsub("%..*", "")
|
||||||
|
desc = desc:sub(1, 1):upper() .. desc:sub(2)
|
||||||
|
desc = (key:sub(1, 1) == "[" and "Prev " or "Next ") .. desc
|
||||||
|
desc = desc .. (key:sub(2, 2) == key:sub(2, 2):upper() and " End" or " Start")
|
||||||
|
if not (vim.wo.diff and key:find("[cC]")) then
|
||||||
|
vim.keymap.set({ "n", "x", "o" }, key, function()
|
||||||
|
require("nvim-treesitter-textobjects.move")[method](query, "textobjects")
|
||||||
|
end, {
|
||||||
|
buffer = buf,
|
||||||
|
desc = desc,
|
||||||
|
silent = true,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
group = vim.api.nvim_create_augroup("lazyvim_treesitter_textobjects", { clear = true }),
|
group = vim.api.nvim_create_augroup("lazyvim_treesitter_textobjects", { clear = true }),
|
||||||
callback = function(ev)
|
callback = function(ev)
|
||||||
if not (vim.tbl_get(opts, "move", "enable") and LazyVim.treesitter.have(ev.match, "textobjects")) then
|
attach(ev.buf)
|
||||||
return
|
|
||||||
end
|
|
||||||
---@type table<string, table<string, string>>
|
|
||||||
local moves = vim.tbl_get(opts, "move", "keys") or {}
|
|
||||||
|
|
||||||
for method, keymaps in pairs(moves) do
|
|
||||||
for key, query in pairs(keymaps) do
|
|
||||||
local desc = query:gsub("@", ""):gsub("%..*", "")
|
|
||||||
desc = desc:sub(1, 1):upper() .. desc:sub(2)
|
|
||||||
desc = (key:sub(1, 1) == "[" and "Prev " or "Next ") .. desc
|
|
||||||
desc = desc .. (key:sub(2, 2) == key:sub(2, 2):upper() and " End" or " Start")
|
|
||||||
if not (vim.wo.diff and key:find("[cC]")) then
|
|
||||||
vim.keymap.set({ "n", "x", "o" }, key, function()
|
|
||||||
require("nvim-treesitter-textobjects.move")[method](query, "textobjects")
|
|
||||||
end, {
|
|
||||||
buffer = ev.buf,
|
|
||||||
desc = desc,
|
|
||||||
silent = true,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
vim.tbl_map(attach, vim.api.nvim_list_bufs())
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue