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.
This commit is contained in:
Sanchayan Maity 2022-11-07 13:57:53 +05:30
parent ef4c3b7d30
commit 397cac1050
2 changed files with 4 additions and 71 deletions

View File

@ -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",
},
},

View File

@ -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 = {
["<Leader>sb"] = "@block.outer" ,
["<Leader>sl"] = "@call.outer" ,
["<Leader>sc"] = "@class.outer" ,
["<Leader>sf"] = "@function.outer" ,
["<Leader>sp"] = "@parameter.inner",
["<Leader>ss"] = "@statement.outer",
},
swap_previous = {
["<Leader>sB"] = "@block.outer" ,
["<Leader>sL"] = "@call.outer" ,
["<Leader>sC"] = "@class.outer" ,
["<Leader>sF"] = "@function.outer" ,
["<Leader>sP"] = "@parameter.inner",
["<Leader>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', '<Leader>m', ':<C-U>lua require(\'tsht\').nodes()<CR>', { noremap=false, unique=true, silent=true })
vim.keymap.set('x', '<Leader>m', ':lua require(\'tsht\').nodes()<CR>' , { noremap=true , unique=true, silent=true })