Skip to content

Instantly share code, notes, and snippets.

@akaron
Forked from anonymous/markdown-folding.vim
Created July 25, 2016 10:39
Show Gist options
  • Save akaron/7ced117bafa8bf945e8bff9e9b0b81fe to your computer and use it in GitHub Desktop.
Save akaron/7ced117bafa8bf945e8bff9e9b0b81fe 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