Created
December 12, 2012 09:13
-
-
Save mogelbrod/4266297 to your computer and use it in GitHub Desktop.
Vim fold function which does indentation based folding.
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! IndentationFoldExpr(ln) " {{{ | |
let line = getline(a:ln) | |
if line =~ '^\s*$' | |
return '-1' "'=' | |
end | |
let ind = indent(a:ln) / &sw | |
let ind_next = indent(nextnonblank(a:ln+1)) / &sw | |
if ind_next <= ind | |
return ind | |
elseif ind_next > ind | |
return '>'.ind_next | |
end | |
endfunction " }}} | |
au FileType txt setlocal foldmethod=expr foldexpr=IndentationFoldExpr(v:lnum) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment