From 4d5f24d6c1ecd1c77aded7fc4e59a329d27509b8 Mon Sep 17 00:00:00 2001 From: Ashraf Michail Date: Sat, 30 Sep 2023 00:35:22 +0000 Subject: Defer Treesitter setup to improve startup time of nvim {filename} --- init.lua | 113 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 58 insertions(+), 55 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index 5257113..e5bc576 100644 --- a/init.lua +++ b/init.lua @@ -321,69 +321,72 @@ vim.keymap.set('n', 'sr', require('telescope.builtin').resume, { desc = -- [[ Configure Treesitter ]] -- See `:help nvim-treesitter` -require('nvim-treesitter.configs').setup { - -- Add languages to be installed here that you want installed for treesitter - ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim' }, - - -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) - auto_install = false, - - highlight = { enable = true }, - indent = { enable = true }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = '', - node_incremental = '', - scope_incremental = '', - node_decremental = '', - }, - }, - textobjects = { - select = { +-- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}' +vim.defer_fn(function() + require('nvim-treesitter.configs').setup { + -- Add languages to be installed here that you want installed for treesitter + ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim' }, + + -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!) + auto_install = false, + + highlight = { enable = true }, + indent = { enable = true }, + incremental_selection = { enable = true, - lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim keymaps = { - -- You can use the capture groups defined in textobjects.scm - ['aa'] = '@parameter.outer', - ['ia'] = '@parameter.inner', - ['af'] = '@function.outer', - ['if'] = '@function.inner', - ['ac'] = '@class.outer', - ['ic'] = '@class.inner', + init_selection = '', + node_incremental = '', + scope_incremental = '', + node_decremental = '', }, }, - move = { - enable = true, - set_jumps = true, -- whether to set jumps in the jumplist - goto_next_start = { - [']m'] = '@function.outer', - [']]'] = '@class.outer', + 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 + ['aa'] = '@parameter.outer', + ['ia'] = '@parameter.inner', + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['ac'] = '@class.outer', + ['ic'] = '@class.inner', + }, }, - goto_next_end = { - [']M'] = '@function.outer', - [']['] = '@class.outer', + 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', + }, }, - goto_previous_start = { - ['[m'] = '@function.outer', - ['[['] = '@class.outer', - }, - goto_previous_end = { - ['[M'] = '@function.outer', - ['[]'] = '@class.outer', + swap = { + enable = true, + swap_next = { + ['a'] = '@parameter.inner', + }, + swap_previous = { + ['A'] = '@parameter.inner', + }, }, }, - swap = { - enable = true, - swap_next = { - ['a'] = '@parameter.inner', - }, - swap_previous = { - ['A'] = '@parameter.inner', - }, - }, - }, -} + } +end, 0) -- Diagnostic keymaps vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' }) -- cgit v1.2.3