From 0ab4b001a573cda44d461143f2c17a096e670944 Mon Sep 17 00:00:00 2001 From: brustybee Date: Mon, 9 Mar 2026 22:53:31 +0530 Subject: update nvim-treesitter-textobjects and cleanup --- lua/plugins/tsitter.lua | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'lua/plugins/tsitter.lua') diff --git a/lua/plugins/tsitter.lua b/lua/plugins/tsitter.lua index 8bdb0ca..9cbb122 100644 --- a/lua/plugins/tsitter.lua +++ b/lua/plugins/tsitter.lua @@ -43,8 +43,10 @@ return { }) end, }, + { "nvim-treesitter-textobjects", + auto_enable = true, lazy = false, before = function(plugin) -- https://github.com/nvim-treesitter/nvim-treesitter-textobjects/tree/main?tab=readme-ov-file#using-a-package-manager @@ -86,6 +88,9 @@ return { -- and should return true of false include_surrounding_whitespace = false, }, + move = { + set_jumps = true, + }, }) -- keymaps @@ -106,6 +111,71 @@ return { vim.keymap.set({ "x", "o" }, "as", function() require("nvim-treesitter-textobjects.select").select_textobject("@local.scope", "locals") end) + vim.keymap.set("n", "a", function() + require("nvim-treesitter-textobjects.swap").swap_next("@parameter.inner") + end) + vim.keymap.set("n", "A", function() + require("nvim-treesitter-textobjects.swap").swap_previous("@parameter.outer") + end) + + -- You can use the capture groups defined in `textobjects.scm` + vim.keymap.set({ "n", "x", "o" }, "]m", function() + require("nvim-treesitter-textobjects.move").goto_next_start("@function.outer", "textobjects") + end) + vim.keymap.set({ "n", "x", "o" }, "]]", function() + require("nvim-treesitter-textobjects.move").goto_next_start("@class.outer", "textobjects") + end) + -- You can also pass a list to group multiple queries. + vim.keymap.set({ "n", "x", "o" }, "]o", function() + require("nvim-treesitter-textobjects.move").goto_next_start( + { "@loop.inner", "@loop.outer" }, + "textobjects" + ) + end) + -- You can also use captures from other query groups like `locals.scm` or `folds.scm` + vim.keymap.set({ "n", "x", "o" }, "]s", function() + require("nvim-treesitter-textobjects.move").goto_next_start("@local.scope", "locals") + end) + vim.keymap.set({ "n", "x", "o" }, "]z", function() + require("nvim-treesitter-textobjects.move").goto_next_start("@fold", "folds") + end) + + vim.keymap.set({ "n", "x", "o" }, "]M", function() + require("nvim-treesitter-textobjects.move").goto_next_end("@function.outer", "textobjects") + end) + vim.keymap.set({ "n", "x", "o" }, "][", function() + require("nvim-treesitter-textobjects.move").goto_next_end("@class.outer", "textobjects") + end) + + vim.keymap.set({ "n", "x", "o" }, "[m", function() + require("nvim-treesitter-textobjects.move").goto_previous_start("@function.outer", "textobjects") + end) + vim.keymap.set({ "n", "x", "o" }, "[[", function() + require("nvim-treesitter-textobjects.move").goto_previous_start("@class.outer", "textobjects") + end) + + vim.keymap.set({ "n", "x", "o" }, "[M", function() + require("nvim-treesitter-textobjects.move").goto_previous_end("@function.outer", "textobjects") + end) + vim.keymap.set({ "n", "x", "o" }, "[]", function() + require("nvim-treesitter-textobjects.move").goto_previous_end("@class.outer", "textobjects") + end) + local ts_repeat_move = require("nvim-treesitter-textobjects.repeatable_move") + + -- Repeat movement with ; and , + -- ensure ; goes forward and , goes backward regardless of the last direction + -- vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move_next) + -- vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_previous) + + -- vim way: ; goes to the direction you were moving. + vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move) + vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_opposite) + + -- Optionally, make builtin f, F, t, T also repeatable with ; and , + vim.keymap.set({ "n", "x", "o" }, "f", ts_repeat_move.builtin_f_expr, { expr = true }) + vim.keymap.set({ "n", "x", "o" }, "F", ts_repeat_move.builtin_F_expr, { expr = true }) + vim.keymap.set({ "n", "x", "o" }, "t", ts_repeat_move.builtin_t_expr, { expr = true }) + vim.keymap.set({ "n", "x", "o" }, "T", ts_repeat_move.builtin_T_expr, { expr = true }) -- NOTE: for more textobjects options, see the following link. -- This template is using the new `main` branch of the repo. -- cgit v1.3.1