mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-12-25 12:14:19 +01:00
This commit is contained in:
@@ -19,7 +19,6 @@ return {
|
||||
TS.update(nil, { summary = true })
|
||||
end)
|
||||
end,
|
||||
lazy = vim.fn.argc(-1) == 0, -- load treesitter early when opening a file from the cmdline
|
||||
event = { "LazyFile", "VeryLazy" },
|
||||
cmd = { "TSUpdate", "TSInstall", "TSLog", "TSUninstall" },
|
||||
opts_extend = { "ensure_installed" },
|
||||
@@ -162,34 +161,40 @@ return {
|
||||
end
|
||||
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", {
|
||||
group = vim.api.nvim_create_augroup("lazyvim_treesitter_textobjects", { clear = true }),
|
||||
callback = function(ev)
|
||||
if not (vim.tbl_get(opts, "move", "enable") and LazyVim.treesitter.have(ev.match, "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 = ev.buf,
|
||||
desc = desc,
|
||||
silent = true,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
attach(ev.buf)
|
||||
end,
|
||||
})
|
||||
vim.tbl_map(attach, vim.api.nvim_list_bufs())
|
||||
end,
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user