I'd like to fold text between beginning markers like:
//// Block 1
... some code 1 ...
//// Block 2
... some code 2 ...
where ////
would be used as the beginning marker and folding //// Block 1
would fold to the line before //// Block 2
.
Is this something that's possible?
It doesn't like it if I set foldmarker
without an ending parameter and it folds too much if I use ////
as both the beginning and ending markers.
I could manually create folds with zf
, but those are file dependent and break if you change it.
You can write your own fold expression like this:
function! BlockFolds()
let thisline = getline(v:lnum)
if match(thisline, '^\/\/\/\/ Block') >= 0
return ">1"
else
return "="
endif
endfunction
setlocal foldmethod=expr
setlocal foldexpr=BlockFolds()
If you source it in vim you will get the desired effect:
Obviously you can source it in your .vimrc
or based on file extension.
You can understand how custom fold expressions work here: http://vimcasts.org/episodes/writing-a-custom-fold-expression/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With