Add auto-fold on open script, but only fold to first level:
local function applyFoldsAndThenCloseAllFolds(bufnr, providerName)
require("async")(function()
bufnr = bufnr or vim.api.nvim_get_current_buf()
-- make sure buffer is attached
require("ufo").attach(bufnr)
local ranges = require("ufo").getFolds(bufnr, providerName)
local ok = require("ufo").applyFolds(bufnr, ranges)
if ok then require("ufo").closeFoldsWith(1) end
end)
end
vim.api.nvim_create_autocmd("BufRead", {
pattern = "*",
callback = function(e) applyFoldsAndThenCloseAllFolds(e.buf, "treesitter") end,
})
Expected behavior
All folds upto first level are closed when file is opened.
Actual behavior
Only those folds that are visible are closed, if I scroll down the code is not folded.
Neovim version (nvim -v | head -n1)
NVIM v0.9.4
Operating system/version
Ubuntu 22.04
How to reproduce the issue
Add auto-fold on open script, but only fold to first level:
Expected behavior
All folds upto first level are closed when file is opened.
Actual behavior
Only those folds that are visible are closed, if I scroll down the code is not folded.