You can define a normal mode map as follows:
:nnoremap <Leader>f zMzO
zMcloses all the folds in the current file (which will add the current function), then zOrecursively opens the fold under the cursor (which expands the current function).
It is assumed that you :set foldmethod=syntax; it will not necessarily work with other types of folding.
source
share