From bf88d45a5807b4f877c4449d1e63625166edf5f8 Mon Sep 17 00:00:00 2001 From: Salar Rahmanian Date: Wed, 14 Jul 2021 23:28:30 -0700 Subject: [PATCH] Add config for treesitter extensions & setup playground --- programs/neovim/init.lua | 69 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/programs/neovim/init.lua b/programs/neovim/init.lua index 7309e11..ef8f125 100644 --- a/programs/neovim/init.lua +++ b/programs/neovim/init.lua @@ -10,6 +10,7 @@ local function load_plugins() require('packer').startup(function() use 'wbthomason/packer.nvim' -- Package manager use 'nvim-treesitter/nvim-treesitter' + use 'nvim-treesitter/nvim-treesitter-textobjects' use 'folke/which-key.nvim' use 'tpope/vim-commentary' -- "gc" to comment visual regions/lines use {'nvim-telescope/telescope.nvim', requires = {{'nvim-lua/popup.nvim'}, {'nvim-lua/plenary.nvim'}} } @@ -28,6 +29,7 @@ local function load_plugins() use 'scalameta/nvim-metals' use 'ray-x/lsp_signature.nvim' use { 'folke/trouble.nvim', requires = 'kyazdani42/nvim-web-devicons' } + use 'nvim-treesitter/playground' end) end @@ -40,7 +42,7 @@ _G.load_config = function() require("salargalaxyline") -- Treesitter - require("nvim-treesitter.configs").setup({ + require('nvim-treesitter.configs').setup { playground = { enable = true }, query_linter = { enable = true, @@ -49,7 +51,70 @@ _G.load_config = function() }, ensure_installed = "maintained", highlight = { enable = true }, - }) + incremental_selection = { + enable = true, + keymaps = { + init_selection = 'gnn', + node_incremental = 'grn', + scope_incremental = 'grc', + node_decremental = 'grm', + }, + }, + indent = { + enable = true, + }, + textobjects = { + select = { + enable = true, + lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['ac'] = '@class.outer', + ['ic'] = '@class.inner', + }, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + [']m'] = '@function.outer', + [']]'] = '@class.outer', + }, + goto_next_end = { + [']M'] = '@function.outer', + [']['] = '@class.outer', + }, + goto_previous_start = { + ['[m'] = '@function.outer', + ['[['] = '@class.outer', + }, + goto_previous_end = { + ['[M'] = '@function.outer', + ['[]'] = '@class.outer', + }, + }, + }, + playground = { + enable = true, + disable = {}, + updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code + persist_queries = false, -- Whether the query persists across vim sessions + keybindings = { + toggle_query_editor = 'o', + toggle_hl_groups = 'i', + toggle_injected_languages = 't', + toggle_anonymous_nodes = 'a', + toggle_language_display = 'I', + focus_language = 'f', + unfocus_language = 'F', + update = 'R', + goto_node = '', + show_help = '?', + }, + } + } -- neogit require('neogit').setup({