Skip to content

Instantly share code, notes, and snippets.

Created November 26, 2012 18:41
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save anonymous/4149842 to your computer and use it in GitHub Desktop.
Save anonymous/4149842 to your computer and use it in GitHub Desktop.
A simple demo of how a foldexpr works in Vim. See http://vimcasts.org/e/28 for full explanation.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment