1

I like having files be opened folded, specially when they are large. However, when they are small, it can be an overkill (like a markdown file with a single heading). In such cases, I'd like to open top-level folds single level or perhaps unfold everything if the file shorter than some fixed line length (or better -- if it fits on my screen with current size of vim)

How could I achieve this dynamic behavior on startup?

0

Catch BufWinEnter and set foldlevel appropriately

augroup adjust_fold | au!
    autocmd BufWinEnter * let &l:foldlevel = line('$') > 100 ? 0 : line('$') > winheight(0) ? 1 : 99
augroup end
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.