diff --git a/dot_config/lvim/lua/hammy/packer.lua b/dot_config/lvim/lua/hammy/packer.lua index db6c922..47577ea 100644 --- a/dot_config/lvim/lua/hammy/packer.lua +++ b/dot_config/lvim/lua/hammy/packer.lua @@ -4,6 +4,7 @@ lvim.plugins = { { "gpanders/editorconfig.nvim" }, { "p00f/nvim-ts-rainbow" }, { "nvim-treesitter/playground" }, + { "nvim-treesitter/nvim-treesitter-textobjects"}, { "simrat39/rust-tools.nvim" }, { "saecki/crates.nvim", diff --git a/dot_config/lvim/lua/hammy/plugin/treesitter.lua b/dot_config/lvim/lua/hammy/plugin/treesitter.lua index 25c1c95..4ad6e97 100644 --- a/dot_config/lvim/lua/hammy/plugin/treesitter.lua +++ b/dot_config/lvim/lua/hammy/plugin/treesitter.lua @@ -1,3 +1,47 @@ lvim.builtin.treesitter.rainbow.enable = true lvim.builtin.treesitter.highlight.enable = true lvim.builtin.treesitter.ensure_installed = "all" +lvim.builtin.treesitter.textobjects = { + select = { + enable = true, + lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ["aa"] = "@parameter.outer", + ["ia"] = "@parameter.inner", + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@class.outer", + ["ic"] = "@class.inner", + }, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + ["]m"] = "@function.outer", + ["]]"] = "@class.outer", + }, + goto_next_end = { + ["]M"] = "@function.outer", + ["]["] = "@class.outer", + }, + goto_previous_start = { + ["[m"] = "@function.outer", + ["[["] = "@class.outer", + }, + goto_previous_end = { + ["[M"] = "@function.outer", + ["[]"] = "@class.outer", + }, + }, + swap = { + enable = true, + swap_next = { + ["a"] = "@parameter.inner", + }, + swap_previous = { + ["A"] = "@parameter.inner", + }, + }, +}