From 397cac1050f73486806ff4d98e465744d63634a1 Mon Sep 17 00:00:00 2001 From: Sanchayan Maity Date: Mon, 7 Nov 2022 13:57:53 +0530 Subject: [PATCH] nvim: plugins/treesitter: Use treehopper instead of textobjects The whole bunch of treesitter text objects were difficult to remember and we ended up rarely ever using any of the defined mappings. treehopper simplifies things with a single mapping and hints. --- nvim/.config/nvim/lua/plugins.lua | 3 +- nvim/.config/nvim/lua/treesitter.lua | 72 ++-------------------------- 2 files changed, 4 insertions(+), 71 deletions(-) diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index 6c2405f..129637a 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -75,8 +75,7 @@ local init = function () cmd = { "TSPlaygroundToggle", "TSHighlightCapturesUnderCursor" }, }, { - "nvim-treesitter/nvim-treesitter-textobjects", - module = "nvim-treesitter-textobjects", + "mfussenegger/nvim-treehopper", after = "nvim-treesitter", }, }, diff --git a/nvim/.config/nvim/lua/treesitter.lua b/nvim/.config/nvim/lua/treesitter.lua index f16b477..0d597c1 100644 --- a/nvim/.config/nvim/lua/treesitter.lua +++ b/nvim/.config/nvim/lua/treesitter.lua @@ -1,78 +1,9 @@ --- Required to enable textobjects. See --- https://github.com/nvim-treesitter/nvim-treesitter-textobjects/issues/100. -require'nvim-treesitter-textobjects' - local ts_langs = { "bash", "cpp", "fish", "go", "haskell", "html", "java", "javascript", "jsdoc", "json", "markdown", "nix", "python", "query", "rust", "teal", "toml", "tsx", "typescript", "verilog" } require'nvim-treesitter.install'.compilers = { "gcc" } require'nvim-treesitter.configs'.setup { ensure_installed = ts_langs, highlight = { enable = true, }, - textobjects = { - select = { - enable = true, - lookahead = true, - keymaps = { - ["ab"] = "@block.outer" , - ["ib"] = "@block.inner" , - -- We use M,m for call/conditional as C/c would conflict with textobj-word-column - ["aM"] = "@call.outer" , - ["iM"] = "@call.inner" , - ["ao"] = "@class.outer" , - ["io"] = "@class.inner" , - ["at"] = "@comment.outer" , - ["am"] = "@conditional.outer", - ["im"] = "@conditional.inner", - ["af"] = "@function.outer" , - ["if"] = "@function.inner" , - ["al"] = "@loop.outer" , - ["il"] = "@loop.inner" , - ["ap"] = "@parameter.outer" , - ["ip"] = "@parameter.inner" , - ["is"] = "@scopename.inner" , - ["as"] = "@statement.outer" , - }, - }, - swap = { - enable = true, - swap_next = { - ["sb"] = "@block.outer" , - ["sl"] = "@call.outer" , - ["sc"] = "@class.outer" , - ["sf"] = "@function.outer" , - ["sp"] = "@parameter.inner", - ["ss"] = "@statement.outer", - }, - swap_previous = { - ["sB"] = "@block.outer" , - ["sL"] = "@call.outer" , - ["sC"] = "@class.outer" , - ["sF"] = "@function.outer" , - ["sP"] = "@parameter.inner", - ["sS"] = "@statement.outer", - }, - }, - move = { - enable = true, - set_jumps = true, - goto_next_start = { - ["]m"] = "@function.outer", - ["]s"] = "@class.outer", - }, - goto_next_end = { - ["]M"] = "@function.outer", - ["]S"] = "@class.outer", - }, - goto_previous_start = { - ["[m"] = "@function.outer", - ["[s"] = "@class.outer", - }, - goto_previous_end = { - ["[M"] = "@function.outer", - ["[S"] = "@class.outer", - }, - }, - }, query_linter = { enable = true, use_virtual_text = true, @@ -100,3 +31,6 @@ require'nvim-treesitter.configs'.setup { enable = true, }, } + +vim.keymap.set('o', 'm', ':lua require(\'tsht\').nodes()', { noremap=false, unique=true, silent=true }) +vim.keymap.set('x', 'm', ':lua require(\'tsht\').nodes()' , { noremap=true , unique=true, silent=true })