Ref to :h foldtext()
The number of leading dashes depends on the foldlevel.
As follow, I think the foldlevel of printf
is 1.
But, you can see as follow, the number of dashes is 2.
I can't understand why inconsist
The documentation does not say how many dashes are there per foldlevel. As can be seen in the source:
txt = NGETTEXT("+-%s%3ld line: ", "+-%s%3ld lines: ", count);
r = alloc((unsigned)(STRLEN(txt)
+ STRLEN(dashes) /* for %s */
+ 20 /* for %3ld */
+ STRLEN(s))); /* concatenated */
if (r != NULL)
{
sprintf((char *)r, txt, dashes, count);
len = (int)STRLEN(r);
STRCAT(r, s);
/* remove 'foldmarker' and 'commentstring' */
foldtext_cleanup(r + len);
rettv->vval.v_string = r;
}
So you can see, the number of dashes is actually equal to the foldlevel + 1
As @Christian Brabandt showed from the source code, the string used for folding has a "+-" at the beginning of the string, resulting in the foldlevel+1
dashes. I can't answer whether this is intentional or a bug. You could open an issue on the vim github if you feel that this is a bug, and you will hopefully receive either justification for the extra dash or the "bug" will be fixed.
If you would like a "fix" for this, you can add the following to your vimrc:
function MyFoldText()
let line = getline(v:foldstart)
let sub = substitute(line, '^\s*\|//\s*\|/\*\|\*/\|{{{\d\=', '', 'g')
let oneLessDash = strpart(string(v:folddashes),1,len(string(v:folddashes))-2)
let foldlinecount = foldclosedend(v:foldstart) - foldclosed(v:foldstart) + 1
let lineCount = " " . string(foldlinecount) . " lines: "
return "+" . oneLessDash . lineCount . sub
endfunction
set foldtext=MyFoldText()
This will print the same foldtext
as before with just one less dash.
P.S. Welcome to the community!