public
Last active

Vim fold function which does indentation based folding.

  • Download Gist
gistfile1.vim
VimL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.