Skip to content

Commit ddcda94

Browse files
Defer Treesitter setup to improve startup time of nvim {filename}
1 parent f5b7dd9 commit ddcda94

File tree

1 file changed

+58
-55
lines changed

1 file changed

+58
-55
lines changed

init.lua

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -321,69 +321,72 @@ vim.keymap.set('n', '<leader>sr', require('telescope.builtin').resume, { desc =
321321

322322
-- [[ Configure Treesitter ]]
323323
-- See `:help nvim-treesitter`
324-
require('nvim-treesitter.configs').setup {
325-
-- Add languages to be installed here that you want installed for treesitter
326-
ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim' },
327-
328-
-- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
329-
auto_install = false,
330-
331-
highlight = { enable = true },
332-
indent = { enable = true },
333-
incremental_selection = {
334-
enable = true,
335-
keymaps = {
336-
init_selection = '<c-space>',
337-
node_incremental = '<c-space>',
338-
scope_incremental = '<c-s>',
339-
node_decremental = '<M-space>',
340-
},
341-
},
342-
textobjects = {
343-
select = {
324+
-- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}'
325+
vim.defer_fn(function()
326+
require('nvim-treesitter.configs').setup {
327+
-- Add languages to be installed here that you want installed for treesitter
328+
ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim' },
329+
330+
-- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
331+
auto_install = false,
332+
333+
highlight = { enable = true },
334+
indent = { enable = true },
335+
incremental_selection = {
344336
enable = true,
345-
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
346337
keymaps = {
347-
-- You can use the capture groups defined in textobjects.scm
348-
['aa'] = '@parameter.outer',
349-
['ia'] = '@parameter.inner',
350-
['af'] = '@function.outer',
351-
['if'] = '@function.inner',
352-
['ac'] = '@class.outer',
353-
['ic'] = '@class.inner',
338+
init_selection = '<c-space>',
339+
node_incremental = '<c-space>',
340+
scope_incremental = '<c-s>',
341+
node_decremental = '<M-space>',
354342
},
355343
},
356-
move = {
357-
enable = true,
358-
set_jumps = true, -- whether to set jumps in the jumplist
359-
goto_next_start = {
360-
[']m'] = '@function.outer',
361-
[']]'] = '@class.outer',
344+
textobjects = {
345+
select = {
346+
enable = true,
347+
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
348+
keymaps = {
349+
-- You can use the capture groups defined in textobjects.scm
350+
['aa'] = '@parameter.outer',
351+
['ia'] = '@parameter.inner',
352+
['af'] = '@function.outer',
353+
['if'] = '@function.inner',
354+
['ac'] = '@class.outer',
355+
['ic'] = '@class.inner',
356+
},
362357
},
363-
goto_next_end = {
364-
[']M'] = '@function.outer',
365-
[']['] = '@class.outer',
358+
move = {
359+
enable = true,
360+
set_jumps = true, -- whether to set jumps in the jumplist
361+
goto_next_start = {
362+
[']m'] = '@function.outer',
363+
[']]'] = '@class.outer',
364+
},
365+
goto_next_end = {
366+
[']M'] = '@function.outer',
367+
[']['] = '@class.outer',
368+
},
369+
goto_previous_start = {
370+
['[m'] = '@function.outer',
371+
['[['] = '@class.outer',
372+
},
373+
goto_previous_end = {
374+
['[M'] = '@function.outer',
375+
['[]'] = '@class.outer',
376+
},
366377
},
367-
goto_previous_start = {
368-
['[m'] = '@function.outer',
369-
['[['] = '@class.outer',
370-
},
371-
goto_previous_end = {
372-
['[M'] = '@function.outer',
373-
['[]'] = '@class.outer',
378+
swap = {
379+
enable = true,
380+
swap_next = {
381+
['<leader>a'] = '@parameter.inner',
382+
},
383+
swap_previous = {
384+
['<leader>A'] = '@parameter.inner',
385+
},
374386
},
375387
},
376-
swap = {
377-
enable = true,
378-
swap_next = {
379-
['<leader>a'] = '@parameter.inner',
380-
},
381-
swap_previous = {
382-
['<leader>A'] = '@parameter.inner',
383-
},
384-
},
385-
},
386-
}
388+
}
389+
end, 0)
387390

388391
-- Diagnostic keymaps
389392
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous diagnostic message' })

0 commit comments

Comments
 (0)