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 },
53 incremental_selection = {
56 init_selection = "<C-space>",
57 node_incremental = "<C-space>",
58 scope_incremental = false,
59 node_decremental = "<bs>",
65 goto_next_start = { ["]f"] = "@function.outer", ["]c"] = "@class.outer", ["]a"] = "@parameter.inner" },
66 goto_next_end = { ["]F"] = "@function.outer", ["]C"] = "@class.outer", ["]A"] = "@parameter.inner" },
67 goto_previous_start = { ["[f"] = "@function.outer", ["[c"] = "@class.outer", ["[a"] = "@parameter.inner" },
68 goto_previous_end = { ["[F"] = "@function.outer", ["[C"] = "@class.outer", ["[A"] = "@parameter.inner" },
72 ---@param opts TSConfig
73 config = function(_, opts)
74 -- make sure extra langs are not duplicated
75 opts.ensure_installed = rmz.dedup(opts.ensure_installed)
77 local configs = require("nvim-treesitter.configs")
80 -- When in diff mode, we want to use the default
81 -- vim text objects c & C instead of the treesitter ones.
82 local move = require("nvim-treesitter.textobjects.move") ---@type table<string,fun(...)>
83 for name, fn in pairs(move) do
84 if name:find("goto") == 1 then
85 move[name] = function(q, ...)
86 if not vim.wo.diff then return fn(q, ...) end
88 local config = configs.get_module("textobjects.move")[name] ---@type table<string,string>
89 for key, query in pairs(config or {}) do
90 if q == query and key:find("[%]%[][cC]") then
91 vim.cmd("normal! " .. key)
101 -- Automatically add closing tags for HTML and JSX
103 "windwp/nvim-ts-autotag",