From 3a6810451627a2f8591fe475d1f5eb86a191b7ab Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Fri, 1 Sep 2023 13:52:41 -0500 Subject: [PATCH] feat(nvim): add ts-textobjects --- .../nvim/lua/plugins/configs/treesitter.lua | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/dots/.config/nvim/lua/plugins/configs/treesitter.lua b/dots/.config/nvim/lua/plugins/configs/treesitter.lua index 88ebf1d3..d6cb790c 100644 --- a/dots/.config/nvim/lua/plugins/configs/treesitter.lua +++ b/dots/.config/nvim/lua/plugins/configs/treesitter.lua @@ -121,6 +121,7 @@ return { config = true, }, "JoosepAlviste/nvim-ts-context-commentstring", + "nvim-treesitter/nvim-treesitter-textobjects", }, config = function() local treesitter_dir = vim.fn.stdpath("data") .. "/treesitter" @@ -177,6 +178,59 @@ return { context_commentstring = { enable = true, }, + textobjects = { + select = { + enable = true, + lookahead = true, + disable = function(lang, bufnr) + local mode = vim.fn.mode() + if mode == "c" then + return true + end + end, + keymaps = { + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@class.outer", + ["ic"] = "@class.inner", + ["ib"] = "@block.inner", + ["ab"] = "@block.outer", + ["as"] = { query = "@scope", query_group = "locals", desc = "Select language scope" }, + }, + }, + move = { + enable = true, + disable = function(lang, bufnr) + local mode = vim.fn.mode() + if mode == "c" then + return true + end + end, + set_jumps = true, + goto_next_start = { + ["]fs"] = "@function.outer", + ["]cs"] = "@class.outer", + ["]bs"] = "@block.outer", + }, + goto_next_end = { + ["]fe"] = "@function.outer", + ["]ce"] = "@class.outer", + ["]be"] = "@block.outer", + }, + goto_previous_start = { + ["[fs"] = "@function.outer", + ["[cs"] = "@class.outer", + ["[bs"] = "@block.outer", + }, + goto_previous_end = { + ["[fe"] = "@function.outer", + ["[ce"] = "@class.outer", + ["[bs"] = "@block.outer", + }, + }, + include_surrounding_whitespace = true, + }, + }) end, },