return { { -- Highlight, edit, and navigate code 'nvim-treesitter/nvim-treesitter', lazy = false, branch = 'main', build = ':TSUpdate', opts = {}, -- main = 'nvim-treesitter.configs', -- Sets main module to use for opts -- [[ Configure Treesitter ]] See `:help nvim-treesitter` config = function() local ensureInstalled = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc', 'go', 'rust', 'elixir', 'toml' } local alreadyInstalled = require('nvim-treesitter').get_installed 'parsers' local parsersToInstall = vim .iter(ensureInstalled) :filter(function(parser) return not vim.tbl_contains(alreadyInstalled, parser) end) :totable() print(parsersToInstall) if #parsersToInstall > 0 then require('nvim-treesitter').install(parsersToInstall) end local parsersInstalled = require('nvim-treesitter').get_installed 'parsers' for _, parser in pairs(parsersInstalled) do local filetypes = vim.treesitter.language.get_filetypes(parser) vim.api.nvim_create_autocmd({ 'FileType' }, { group = vim.api.nvim_create_augroup('EnableTreesitterHighlighting', { clear = true }), pattern = filetypes, callback = function(event) print(event.buf) local parser_installed = pcall(vim.treesitter.get_parser, event.buf, parser) if parser_installed then pcall(vim.treesitter.start, event.buf, parser) end end, }) end end, -- There are additional nvim-treesitter modules that you can use to interact -- with nvim-treesitter. You should go explore a few and see what interests you: -- -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod` -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context }, { 'nvim-treesitter/nvim-treesitter-textobjects', opts = {}, branch = 'main', config = function() require('nvim-treesitter-textobjects').setup { select = { -- Automatically jump forward to textobj, similar to targets.vim lookahead = true, }, } vim.keymap.set({ 'x', 'o' }, 'af', function() require('nvim-treesitter-textobjects.select').select_textobject('@function.outer', 'textobjects') end, { desc = 'Select outer function' }) vim.keymap.set({ 'x', 'o' }, 'if', function() require('nvim-treesitter-textobjects.select').select_textobject('@function.inner', 'textobjects') end, { desc = 'Select inside function' }) vim.keymap.set({ 'x', 'o' }, 'ac', function() require('nvim-treesitter-textobjects.select').select_textobject('@class.outer', 'textobjects') end, { desc = 'Select outer class' }) vim.keymap.set({ 'x', 'o' }, 'ic', function() require('nvim-treesitter-textobjects.select').select_textobject('@class.inner', 'textobjects') end, { desc = 'Select outer class' }) end, }, } -- vim: ts=2 sts=2 sw=2 et