我已经为 Markdown 实现了一个非常简单的折叠表达式,但由于某些原因它并没有起作用。我已经在echom
函数中插入了一些FoldExpr
消息,我可以在消息中看到它们并且它们是正确的。所以似乎应用了,但没有折叠。除了我将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 :(得分:0)
>0
没有意义。不幸的是,Vim毫无保留地接受了它。根据{{3}},0
的折叠值表示该行未折叠。要开始一级折叠,请返回>1
。