>> To fold based on that definition, you can use
>>
>>    :set foldmethod=expr
>>    :set foldexpr=strlen(matchstr(getline(v:lnum),'^-*'))
> 
> Shouldn't the pattern be: '^--*'

It shouldn't matter much one way or the other.  It simply returns 
a value of "0" (a perfectly valid value for the foldlevel) if 
there aren't any leading "-"s.  The expression simply returns 
"how many leading dashes are there on the current line?" as the 
fold-level -- if that's zero, then it's zero. :)


If, as the OP later clarified, you want a trailing space, to 
prevent the strlen from getting the wrong-sized input, you can use

   strlen(matchstr(getline(v:lnum),'^-*\\ze\\s'))

which will ensure that there's a space after the dashes (and not 
fold it if there isn't).  You could, if you want to be explicit, 
change it to '^--*' or '^-\\+' to ensure that there's at least 
one dash.  However, because foldexpr accepts "0" as a valid 
value, I wouldn't go to the trouble.

-tim




--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to