Create a gist now

Instantly share code, notes, and snippets.

anonymous /markdown-folding.vim
Created Nov 26, 2012

What would you like to do?
A simple demo of how a foldexpr works in Vim. See for full explanation.
function! MarkdownFolds()
let thisline = getline(v:lnum)
if match(thisline, '^##') >= 0
return ">2"
elseif match(thisline, '^#') >= 0
return ">1"
return "="
setlocal foldmethod=expr
setlocal foldexpr=MarkdownFolds()
function! MarkdownFoldText()
let foldsize = (v:foldend-v:foldstart)
return getline(v:foldstart).' ('.foldsize.' lines)'
setlocal foldtext=MarkdownFoldText()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment