-- -- 50-fold.lua -- -- * Creates an autocommand to fold with treesitter automatically and close all folds on 'FileType'. -- * Sets 'foldlevel' to 99 so that new text will not fold while editing. -- local function fold_with_treesitter() if vim.api.nvim_win_get_config(0).relative ~= "" or vim.treesitter.get_parser(0) == nil then return end vim.opt_local.foldexpr = "v:lua.vim.treesitter.foldexpr()" vim.opt_local.foldmethod = "expr" vim.cmd("silent! %foldclose!") end ---------------------------------------------------------------------------------------------------- vim.api.nvim_create_autocmd("FileType", { desc = "Initialize folds", group = vim.g.dotfiles.augroup, callback = fold_with_treesitter, }) vim.opt.foldenable = true vim.opt.foldlevel = 99