维姆折叠表达式不起作用



>我已经为Markdown实现了一个非常简单的折叠表达式,但由于某种原因它不起作用。我已经在FoldExpr函数中插入了一些echom消息,我可以在消息中看到它们并且它们是正确的。所以它似乎被应用了,但没有褶皱。除了我将foldlevel设置为零之外,zM也没有效果。

有人看到失败了吗?

ftplugin/markdown_fold.vim :

" Generate the folds text for the `foldtext` option.
" Simply use the first line (which should contain the header)
" and extend it by the number of lines in this section.
"
function! FoldText()
let l:title = getline(v:foldstart)
let l:line_count = (v:foldend - v:foldstart)
let l:line_text = l:line_count > 1 ? 'lines' : 'line'
let l:text = l:title . ' [' . l:line_count . ' ' . l:line_text . ']'
return l:text
endfunction
" Return the fold level for the `foldexpr` option.
" Checks if the current line is a header.
" The level is equal to the number of hashes of the header.
" All lines which are not a header have the same level as their predecessor.
"
function! FoldExpr()
let l:line = getline(v:lnum)
let l:count = len(matchstr(l:line, '^#+'))
if l:count > 0
return '>0'
else
return '='
endif
endfunction

" Use custom fold expression and text.
setlocal foldmethod=expr
setlocal foldexpr=FoldExpr()
setlocal foldtext=FoldText()
" Fold everything per default.
setlocal foldlevel=0
setlocal foldminlines=0

这个>0没有意义。不幸的是,Vim毫无怨言地接受了它。根据:help fold-expr,折叠值为0意味着这条线不在折叠中。要开始一级折叠,请改为返回>1

最新更新