return { { "kevinhwang91/nvim-ufo", event = "BufEnter", keys = { { "zR", function() require("ufo").openAllFolds() end, desc = "ufo: open all folds", }, { "zM", function() require("ufo").closeAllFolds() end, desc = "ufo: close all folds", }, { "zr", function() require("ufo").openFoldsExceptKinds() end, desc = "ufo: open folds except kinds", }, { "zm", function() require("ufo").closeFoldsWith() end, desc = "ufo: close folds with" }, { "zp", function() require("ufo").peekFoldedLinesUnderCursor() end, desc = "ufo: peek fold" }, }, dependencies = { "kevinhwang91/promise-async", }, opts = { preview = { mappings = { scrollB = "", scrollF = "", scrollU = "", scrollD = "", }, }, provider_selector = function(_, filetype, buftype) local function handleFallbackException(bufnr, err, providerName) if type(err) == "string" and err:match("UfoFallbackException") then return require("ufo").getFolds(bufnr, providerName) else return require("promise").reject(err) end end return (filetype == "" or buftype == "nofile") and "indent" -- only use indent until a file is opened or function(bufnr) return require("ufo") .getFolds(bufnr, "lsp") :catch(function(err) return handleFallbackException(bufnr, err, "treesitter") end) :catch(function(err) return handleFallbackException(bufnr, err, "indent") end) end end, }, } }