From 7a40a8bf03ba889cb42b0e8c18a662d63e9d0e70 Mon Sep 17 00:00:00 2001 From: Jose Carvajal Date: Fri, 20 Jun 2025 23:28:16 -0600 Subject: [PATCH] Use setup config for setting up treesitter keymaps instead of setting them manually with vim.keymap.set --- lua/kickstart/plugins/treesitter.lua | 33 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lua/kickstart/plugins/treesitter.lua b/lua/kickstart/plugins/treesitter.lua index f675829b..1947e1a6 100644 --- a/lua/kickstart/plugins/treesitter.lua +++ b/lua/kickstart/plugins/treesitter.lua @@ -50,24 +50,25 @@ return { branch = 'main', config = function() require('nvim-treesitter-textobjects').setup { - select = { - -- Automatically jump forward to textobj, similar to targets.vim - lookahead = true, + textobjects = { + select = { + enable = true, + -- Automatically jump forward to textobj, similar to targets.vim + lookahead = true, + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ['af'] = { query = '@function.outer', desc = 'Select outer function region' }, + ['if'] = { query = '@function.inner', desc = 'Select inner function region' }, + ['ac'] = { query = '@class.outer', desc = 'Select outer class region' }, + -- You can optionally set descriptions to the mappings (used in the desc parameter of + -- nvim_buf_set_keymap) which plugins like which-key display + ['ic'] = { query = '@class.inner', desc = 'Select inner class region' }, + -- You can also use captures from other query groups like `locals.scm` + ['as'] = { query = '@local.scope', query_group = 'locals', desc = 'Select language scope' }, + }, + }, }, } - - vim.keymap.set({ 'x', 'o' }, 'af', function() - require('nvim-treesitter-textobjects.select').select_textobject('@function.outer', 'textobjects') - end, { desc = 'Select outer function' }) - vim.keymap.set({ 'x', 'o' }, 'if', function() - require('nvim-treesitter-textobjects.select').select_textobject('@function.inner', 'textobjects') - end, { desc = 'Select inside function' }) - vim.keymap.set({ 'x', 'o' }, 'ac', function() - require('nvim-treesitter-textobjects.select').select_textobject('@class.outer', 'textobjects') - end, { desc = 'Select outer class' }) - vim.keymap.set({ 'x', 'o' }, 'ic', function() - require('nvim-treesitter-textobjects.select').select_textobject('@class.inner', 'textobjects') - end, { desc = 'Select outer class' }) end, }, }