summaryrefslogtreecommitdiff
path: root/lua/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'lua/plugins')
-rw-r--r--lua/plugins/tsitter.lua70
1 files changed, 70 insertions, 0 deletions
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", "<leader>a", function()
+ require("nvim-treesitter-textobjects.swap").swap_next("@parameter.inner")
+ end)
+ vim.keymap.set("n", "<leader>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.