You can accomplish this kind of folding fairly easily by using a file expression, using a function to calculate the fold level of the current line.
You can start a new fold of level n on a line that starts with n *
s (possibly followed by whitespace.) For a line that doesn't start with *
, simply use the fold level of the most recent *
line above it.
That's easily implemented with:
function OrgFold(lnum)
let level = strlen(matchstr(getline(a:lnum), '\v^\s*\zs\*+'))
if level > 0
return '>'.level
else
return '='
endif
endfunction
The folding function can return something like >2
to start a level 2 fold on the current line. Returning =
means use the fold level of the preceding line which had the fold level explicitly set.
Enable this folding with:
set foldmethod=expr foldexpr=OrgFold(v:lnum)
You can customize the text displayed when the block is folded. For example, to simply display the first line followed by three dots, you can use:
set foldtext=getline(v:foldstart).'...'.repeat('\ ',999)
This expression also suppresses the dashes to the right of the fold text, by padding the string with enough spaces to fully hide them.
foldmarker=*,*
, though you'll almost certainly have to use numbers, and it might not work.*
s to always start on the first column.'foldtext'
that does exactly what's on your animations. (Well, except for the highlighting, but I think a lot of that should be doable in Vim as well, though I'm not totally sure whether you can have different styles for different closed folds... Ask a question about that part if you like!)