fixed folding -- again

This commit is contained in:
Mathias Schneider
2026-04-15 18:28:02 +02:00
parent 814860ca63
commit 392f1b7861
3 changed files with 92 additions and 37 deletions
+34 -9
View File
@@ -10,20 +10,45 @@
- vim.go.* for global option shorthand
]]
-- ============================================================================
-- TREESITTER (Built-in Neovim 0.10+ features)
-- ============================================================================
-- Enable Treesitter syntax highlighting (native in Neovim 0.10+)
-- This replaces the old nvim-treesitter highlight module
vim.api.nvim_create_autocmd("FileType", {
pattern = "*",
callback = function()
if vim.bo.buftype == "" and vim.bo.filetype ~= "" then
pcall(vim.treesitter.start)
end
end,
desc = "Enable Treesitter highlighting",
})
-- ============================================================================
-- FOLDING SETTINGS (Code folding)
-- ============================================================================
-- Foldmethod determines how code blocks are detected and folded
-- "expr" means folds are based on expressions (we use treesitter for this)
vim.opt.foldmethod = "expr"
-- Foldexpr is the expression used to determine fold level
-- v:lua.vim.treesitter.foldexpr() uses Treesitter to calculate folds
vim.opt.foldexpr = "v:lua.vim.treesitter.foldexpr()"
-- NOTE: In Neovim 0.10+, Treesitter folding must be set per-buffer via FileType autocmd
-- Setting it globally causes the foldexpr to evaluate before Treesitter attaches
-- Foldlevel: Higher number = more folds are open by default
-- 99 means almost all folds are open when opening a file
vim.opt.foldlevel = 99
-- 1-2 means you'll see folds by default; 99 means all folds are open
vim.opt.foldlevel = 1
vim.opt.foldlevelstart = 1
-- Setup Treesitter folding for each buffer after filetype is detected
-- This ensures the parser is loaded before foldexpr evaluates
vim.api.nvim_create_autocmd("FileType", {
pattern = "*",
callback = function()
-- Only set folding for file buffers with Treesitter support
if vim.bo.buftype == "" then
vim.wo.foldmethod = "expr"
vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()"
end
end,
desc = "Setup Treesitter folding per filetype",
})
-- ============================================================================
-- LINE NUMBERS