summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrustybee <bee@4d2.org>2026-03-09 22:53:31 +0530
committerbrustybee <bee@4d2.org>2026-03-09 22:53:31 +0530
commit0ab4b001a573cda44d461143f2c17a096e670944 (patch)
tree6a7b26cce2a6f4a0643d6614d7e1527e46c91f9e
parent972e5f9c68cc433c5fc26adf92cd25b293a3776a (diff)
update nvim-treesitter-textobjects and cleanup
-rw-r--r--cats.nix1
-rw-r--r--lua/plugins/tsitter.lua70
-rw-r--r--package.nix2
3 files changed, 71 insertions, 2 deletions
diff --git a/cats.nix b/cats.nix
index 42a996a..781313e 100644
--- a/cats.nix
+++ b/cats.nix
@@ -17,7 +17,6 @@ in
fd
ripgrep
lsof
- tree-sitter
# lldb
];
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.
diff --git a/package.nix b/package.nix
index 8a04224..72f0e4e 100644
--- a/package.nix
+++ b/package.nix
@@ -55,7 +55,7 @@ let
baseExtra =
{ pkgs, ... }@misc:
{
- colorscheme = "gruvbox-material";
+ colorscheme = "onedark";
nixdExtras = {
nixpkgs = "import ${pkgs.path} {}";
};