public
anonymous / markdown-folding.vim
Last active

A simple demo of how a foldexpr works in Vim. See http://vimcasts.org/e/28 for full explanation.

  • Download Gist
markdown-folding.vim
VimL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
function! MarkdownFolds()
let thisline = getline(v:lnum)
if match(thisline, '^##') >= 0
return ">2"
elseif match(thisline, '^#') >= 0
return ">1"
else
return "="
endif
endfunction
setlocal foldmethod=expr
setlocal foldexpr=MarkdownFolds()
 
function! MarkdownFoldText()
let foldsize = (v:foldend-v:foldstart)
return getline(v:foldstart).' ('.foldsize.' lines)'
endfunction
setlocal foldtext=MarkdownFoldText()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.