kevinhwang91 / nvim-ufo

Not UFO in the sky, but an ultra fold in Neovim.
BSD 3-Clause "New" or "Revised" License
2.16k stars 37 forks source link

Don't fold when file is short #196

Open Rizhiy opened 5 months ago

Rizhiy commented 5 months ago

Feature description

Disable folding if the file is less than X lines long.

Describe the solution you'd like

I used to have the following code when I was using built-in folding, to disable folding for short files:

local autocmd = vim.api.nvim_create_autocmd
autocmd({ "BufReadPost" }, {
    callback = function(_)
        if vim.api.nvim_buf_line_count(0) > 70 then
            vim.opt.foldlevel = 1
        else
            vim.opt.foldlevel = 10
        end
    end,
})

Is it possible to accomplish the same with ufo?

If not, that would be a nice feature to have.

Additional context

Not much point folding parts, if the whole file already fits on the screen.

kevinhwang91 commented 5 months ago

https://github.com/kevinhwang91/nvim-ufo/blob/b0741a647efd98d9abb6cb653e056d24a07e4581/doc/example.lua#L113-L127

For now, run this snippet in BufReadPost and replace closeAllFolds with closeFoldsWith under the condition.

If users need this feature, upvote this feature.

Mo0rBy commented 1 month ago

Just came across this issue while attempting to search for issues for an equal/opposite feature: "collapse all folds when file is larger than X lines".

Maybe a new feature could be created where a user can define 2 parameters, an upper and lower bound, or 1 parameter, that tells UFO to collapse/open all folds when the file is larger or smaller the given parameter(s).

I'm unsure if there is already a way to do this as I only found this plugin yesterday (and what a great plugin it is too).