I am trying to create a simple Vim script that will create very compact top-level folds for c files. Ideally, if it was running on this code:
static void funca(...) { ... } static void funcb(...) { ... }
Then he will create folds that will look like this:
+-- x Lines: static void funca(...)---------------------- +-- x Lines: static void funcb(...)----------------------
So basically it would be like foldmethod = syntax with foldlevel = 1, except that each summary would start one line further and expand further to include all the following empty lines.
I know how to make one of these folds (assuming foldmethod = manual):
/^{<cr>kVnn?^$<cr>zf
But I'm not sure how to include it in a function. These are my efforts:
function Cfold() set foldmethod=manual " Manual folds ggzE " Delete all folds while (/^{<cr>) " Somehow loop through each match kVnn?^$<cr>zf " This would work fine except for the last function endwhile endfunction map <Leader>f :call Cfold()<cr>
But this is not true, I'm not quite sure how the functions work. In addition, it will not work for the last function in the file, since it will no longer find "^ {". If someone can help me get this work and somehow add a case for the last function to the file, I would be extremely grateful.
Thanks in advance:)
Vincent l
source share