How can I set foldlevelstart in vim to just fold nothing initially, still allowing zr to work immediately?

Solution 1:

This finds the highest foldlevel in the current file:

:let &foldlevel = max(map(range(1, line('$')), 'foldlevel(v:val)'))

To set this automatically, you can use an :autocmd:

:autocmd BufWinEnter * let &foldlevel = max(map(range(1, line('$')), 'foldlevel(v:val)'))