2 { "nvim-treesitter/nvim-treesitter",
3 dependencies = { "nvim-treesitter/nvim-treesitter-textobjects" },
5 event = { "LazyFile", "VeryLazy" },
6 lazy = vim.fn.argc(-1) == 0, -- load treesitter early when opening a file from the cmdline
7 init = function(plugin)
8 -- PERF: add nvim-treesitter queries to the rtp and it's custom query predicates early
9 -- This is needed because a bunch of plugins no longer `require("nvim-treesitter")`, which
10 -- no longer trigger the **nvim-treesitter** module to be loaded in time.
11 -- Luckily, the only things that those plugins need are the custom queries, which we make available
13 require("lazy.core.loader").add_to_rtp(plugin)
14 require("nvim-treesitter.query_predicates")
16 cmd = { "TSUpdateSync", "TSUpdate", "TSInstall" },
18 { "<c-space>", desc = "Increment Selection" },
19 { "<bs>", desc = "Decrement Selection", mode = "x" },
21 opts_extend = { "ensure_installed" },
23 ---@diagnostic disable-next-line: missing-fields
25 highlight = { enable = true },
26 indent = { enable = true },
58 incremental_selection = {
61 init_selection = "<C-space>",
62 node_incremental = "<C-space>",
63 scope_incremental = false,
64 node_decremental = "<bs>",
70 goto_next_start = { ["]f"] = "@function.outer", ["]c"] = "@class.outer", ["]a"] = "@parameter.inner" },
71 goto_next_end = { ["]F"] = "@function.outer", ["]C"] = "@class.outer", ["]A"] = "@parameter.inner" },
72 goto_previous_start = { ["[f"] = "@function.outer", ["[c"] = "@class.outer", ["[a"] = "@parameter.inner" },
73 goto_previous_end = { ["[F"] = "@function.outer", ["[C"] = "@class.outer", ["[A"] = "@parameter.inner" },
77 ---@param opts TSConfig
78 config = function(_, opts)
79 -- make sure extra langs are not duplicated
80 opts.ensure_installed = rmz.dedup(opts.ensure_installed)
82 local configs = require("nvim-treesitter.configs")
85 -- When in diff mode, we want to use the default
86 -- vim text objects c & C instead of the treesitter ones.
87 local move = require("nvim-treesitter.textobjects.move") ---@type table<string,fun(...)>
88 for name, fn in pairs(move) do
89 if name:find("goto") == 1 then
90 move[name] = function(q, ...)
91 if not vim.wo.diff then return fn(q, ...) end
93 local config = configs.get_module("textobjects.move")[name] ---@type table<string,string>
94 for key, query in pairs(config or {}) do
95 if q == query and key:find("[%]%[][cC]") then
96 vim.cmd("normal! " .. key)
106 -- Automatically add closing tags for HTML and JSX
108 "windwp/nvim-ts-autotag",