From a2793f7d7a7989a5c7a2ff8c4da5e049a22fa9ea Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Thu, 5 Feb 2026 15:18:33 +0100 Subject: Neovim: Treesitter-Konfiguration vereinfacht und etwas robuster gestaltet --- nvim/lua/config/autocmds.lua | 37 ++++++++++++------------------------- nvim/lua/config/treesitter.lua | 23 +++++++++++++++++++++++ nvim/lua/plugins/treesitter.lua | 22 ++-------------------- 3 files changed, 37 insertions(+), 45 deletions(-) create mode 100644 nvim/lua/config/treesitter.lua (limited to 'nvim/lua') diff --git a/nvim/lua/config/autocmds.lua b/nvim/lua/config/autocmds.lua index 52c56f9..a4ce4ae 100644 --- a/nvim/lua/config/autocmds.lua +++ b/nvim/lua/config/autocmds.lua @@ -1,30 +1,17 @@ -- https://github.com/nvim-treesitter/nvim-treesitter/blob/main/doc/nvim-treesitter.txt +local treesitter_languages = require("config.treesitter").languages + +local function enable_treesitter_features() + if not pcall(vim.treesitter.start) then return end + + vim.wo.foldmethod = "expr" + vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()" + vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" +end + vim.api.nvim_create_autocmd("FileType", { - pattern = { - "bash", - "c", - "cpp", - "html", - "javascript", - "lua", - "make", - "markdown", - "markdown_inline", - "prisma", - "python", - "typescript", - "vim", - "vim", - "vimdoc", - "yaml", - "zsh", - }, - callback = function() - vim.treesitter.start() - vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()" - vim.wo.foldmethod = "expr" - vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" - end, + pattern = treesitter_languages, + callback = enable_treesitter_features, }) -- https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup diff --git a/nvim/lua/config/treesitter.lua b/nvim/lua/config/treesitter.lua new file mode 100644 index 0000000..c1e25a9 --- /dev/null +++ b/nvim/lua/config/treesitter.lua @@ -0,0 +1,23 @@ +local M = {} + +-- https://github.com/nvim-treesitter/nvim-treesitter/blob/main/SUPPORTED_LANGUAGES.md +M.languages = { + "bash", + "c", + "cpp", + "html", + "javascript", + "lua", + "make", + "markdown", + "markdown_inline", + "prisma", + "python", + "typescript", + "vim", + "vimdoc", + "yaml", + "zsh", +} + +return M diff --git a/nvim/lua/plugins/treesitter.lua b/nvim/lua/plugins/treesitter.lua index 2bbc4c1..235c0b5 100644 --- a/nvim/lua/plugins/treesitter.lua +++ b/nvim/lua/plugins/treesitter.lua @@ -12,29 +12,11 @@ return { lazy = false, config = function() local treesitter = require("nvim-treesitter") + local langs = require("config.treesitter").languages -- treesitter.setup({}) - -- https://github.com/nvim-treesitter/nvim-treesitter/blob/main/SUPPORTED_LANGUAGES.md - treesitter.install({ - "bash", - "c", - "cpp", - "html", - "javascript", - "lua", - "make", - "markdown", - "markdown_inline", - "prisma", - "python", - "typescript", - "vim", - "vim", - "vimdoc", - "yaml", - "zsh", - }) + treesitter.install(langs) end, }, } -- cgit v1.3