From 6da6c47747bbfdb1a59db4f3d38f1dcf9a825f2d Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Thu, 4 Nov 2021 00:48:58 +0200 Subject: [PATCH] feat: add treesitter-textobjects and treesitter-textsubjects --- lua/config/treesitter-textobjects.lua | 25 +++++++++++++++++++ lua/config/treesitter-textsubjects.lua | 9 +++++++ lua/plugins.lua | 34 +++++++++++++++++--------- 3 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 lua/config/treesitter-textobjects.lua create mode 100644 lua/config/treesitter-textsubjects.lua diff --git a/lua/config/treesitter-textobjects.lua b/lua/config/treesitter-textobjects.lua new file mode 100644 index 0000000..bfa6f00 --- /dev/null +++ b/lua/config/treesitter-textobjects.lua @@ -0,0 +1,25 @@ +-- suggested config for selecting text +require'nvim-treesitter.configs'.setup { + 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"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@class.outer", + ["ic"] = "@class.inner", + -- Or you can define your own textobjects like this + -- ["iF"] = { + -- python = "(function_definition) @function", + -- cpp = "(function_definition) @function", + -- c = "(function_definition) @function", + -- java = "(method_declaration) @function", + -- }, + }, + }, + }, +} + diff --git a/lua/config/treesitter-textsubjects.lua b/lua/config/treesitter-textsubjects.lua new file mode 100644 index 0000000..a082245 --- /dev/null +++ b/lua/config/treesitter-textsubjects.lua @@ -0,0 +1,9 @@ +require'nvim-treesitter.configs'.setup { + textsubjects = { + enable = true, + keymaps = { + ['\''] = 'textsubjects-smart', + [';'] = 'textsubjects-container-outer', + } + }, +} diff --git a/lua/plugins.lua b/lua/plugins.lua index a960c67..205de60 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -3,8 +3,6 @@ ---@diagnostic disable-next-line: unused-local local function usePlugins(use, use_rocks) - use {"ray-x/lsp_signature.nvim", config = [[require 'config.lspsignature']]} - -- Packer can manage itself use 'wbthomason/packer.nvim' @@ -25,12 +23,29 @@ local function usePlugins(use, use_rocks) -- Allow repeating use 'tpope/vim-repeat' - -- Tree-sitter + -- Treesitter use { 'nvim-treesitter/nvim-treesitter', config = [[require 'config.treesitter']], + branch = '0.5-compat', run = ':TSUpdate' } + use { + 'nvim-treesitter/playground', + requires = 'nvim-treesitter/nvim-treesitter', + cmd = "TSPlaygroundToggle" + } + use { + 'RRethy/nvim-treesitter-textsubjects', + requires = 'nvim-treesitter/nvim-treesitter', + config = [[require 'config.treesitter-textsubjects']], + } + use { + 'nvim-treesitter/nvim-treesitter-textobjects', + requires = 'nvim-treesitter/nvim-treesitter', + config = [[require 'config.treesitter-textobjects']], + branch = '0.5-compat' + } -- Dev icons use {'kyazdani42/nvim-web-devicons', config = [[require('nvim-web-devicons').setup()]]} @@ -95,6 +110,7 @@ local function usePlugins(use, use_rocks) } -- LSP utils + use {"ray-x/lsp_signature.nvim", config = [[require 'config.lspsignature']]} use { 'RishabhRD/nvim-lsputils', config = [[require 'config.lsputils']], @@ -170,6 +186,10 @@ local function usePlugins(use, use_rocks) -- Load project specific settings from exrc use { 'jenterkin/vim-autosource', config = [[require 'config.autosource']] } + + -- Training plugins + -- use 'tjdevries/train.nvim' + -- use 'ThePrimeagen/vim-be-good' end -- Register custom commands for plugin manager @@ -180,14 +200,6 @@ vim.cmd [[command! PackerSync packadd packer.nvim | lua require('plugins').sync( vim.cmd [[command! PackerClean packadd packer.nvim | lua require('plugins').clean()]] vim.cmd [[command! PackerCompile source lua/plugins.lua | packadd packer.nvim | lua require('plugins').compile()]] --- Run "PackerCompile" whenever this file is updated -vim.cmd [[ - augroup packer_user_config - autocmd! - autocmd BufWritePost plugins.lua source | PackerCompile - augroup end -]] - -- Bootstrap packer.nvim. If packer.nvim is not installed, install it. local function bootstrap() local fn = vim.fn