From 0d04a9812c8692e97b89ae1dcd13a87a586d540c Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Tue, 12 Mar 2024 22:18:13 +0000 Subject: [PATCH] Add tree-sitter based text objects Mappings for: * functions * function arguments/parameters * comments --- lua/plugins/treesitter.lua | 44 +++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua index 460b500..5983425 100644 --- a/lua/plugins/treesitter.lua +++ b/lua/plugins/treesitter.lua @@ -1,13 +1,19 @@ return { 'nvim-treesitter/nvim-treesitter', dependencies = { + 'nvim-treesitter/nvim-treesitter-textobjects', -- TODO: Fork this and add CMake support 'RRethy/nvim-treesitter-endwise', }, build = ':TSUpdate', config = function() require('nvim-treesitter').setup() - local config = { + require('nvim-treesitter.configs').setup({ + sync_install = false, + highlight = { enable = true }, + indent = { enable = true }, + + -- List of languages that must be available ensure_installed = { 'asm', 'bash', @@ -27,6 +33,7 @@ return { 'gitattributes', 'gitignore', 'glsl', + 'go', 'gpg', 'hlsl', 'html', @@ -34,6 +41,7 @@ return { 'javascript', 'jq', 'json', + 'julia', 'llvm', 'lua', 'make', @@ -57,17 +65,29 @@ return { 'xml', 'yaml', }, - sync_install = false, - highlight = { - enable = true, + + -- After opening statements insert end statements + endwise = { enable = true }, + + -- Text objects using Tree-sitter groups + textobjects = { + select = { + enable = true, + lookahead = true, + -- include_surrounding_whitespace = true, + keymaps = { + -- Function text objects + ['af'] = '@function.outer', + ['if'] = '@function.inner', + -- Parameter/argument text objects + ['a,'] = '@parameter.outer', + ['i,'] = '@parameter.inner', + -- Comment text objects + ['a/'] = '@comment.outer', + ['i/'] = '@comment.inner', + }, + }, }, - indent = { - enable = true, - }, - endwise = { - enable = true, - }, - } - require('nvim-treesitter.configs').setup(config) + }) end }