Created
June 7, 2014 13:59
-
-
Save gimKondo/19509aa64a621f08e2be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setlocal foldmethod=expr | |
setlocal foldexpr=MarkdownFold() | |
function! MarkdownFold() | |
let head = s:head(v:lnum) | |
if head | |
return head | |
" end fold of this level when nexe and nexe line is title and nexe line is empty | |
elseif v:lnum + 1 < line('$') && getline(v:lnum + 1) == "" && getline(v:lnum + 2) =~ '^#' | |
return '<' . s:head(v:lnum + 2) | |
" ignore empty line | |
elseif getline(v:lnum) == "" | |
return '=' | |
" end fold of this level when next line is title | |
elseif v:lnum != line('$') && getline(v:lnum + 1) =~ '^#' | |
return '<' . s:head(v:lnum + 1) | |
endif | |
return '=' | |
endfunction | |
function! s:head(lnum) | |
return strlen(matchstr(getline(a:lnum), '^#*')) | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment