local M = {} vim.opt.foldmethod = "expr" vim.opt.foldexpr = "v:lua.vim.treesitter.foldexpr()" vim.opt.foldenable = true vim.opt.foldlevelstart = 2 function M.foldtext() local line = vim.fn.getline(vim.v.foldstart) local hidden = vim.v.foldend - vim.v.foldstart local width = vim.api.nvim_win_get_width(0) local max_width = math.max(20, width - 20) if #line > max_width then line = line:sub(1, max_width - 3) .. "..." end return line .. " [" .. hidden .. " lines]" end vim.opt.foldtext = "v:lua.require('config.fold').foldtext()" return M