Created
November 26, 2012 18:41
-
-
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.
This file contains hidden or 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
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