I have trouble with one specific folding expression, s1
. The documentation (:h fold-expr
) says:
"s1", "s2", .. subtract one, two, .. from the fold level of the previous line
However this is not true for me. Create a file .vim/after/ftplugin/vim/test.vim/
with the following content:
"" This is a demo, the fold starts here. This line has foldlevel 1
" This line is folded wrong, it should have foldlevel 0, but has foldlevel 1
function! VimFolds(lnum)
let thisline = getline(a:lnum)
if match(thisline, '^""') >= 0
return '>1'
elseif match(thisline, '^" ') >= 0
return 's1'
else
return '='
endif
endfunction
setlocal foldmethod=expr
setlocal foldexpr=VimFolds(v:lnum)
set foldcolumn=3
set foldminlines=0
Open the file with Vim, it should be folded according to its own rules. The second line should be on foldlevel 0 according to documentation, but is on foldlevel 1.
Am I understanding something wrong here on how to use this?