" folding based on single space or tabs - from the comments section of: http://vim.wikia.com/wiki/Folding_for_plain_text_files_based_on_indentation
function! TSIndent(line)
return strlen(matchstr(a:line,'\v^\s+'))
endfunction
setlocal foldmethod=expr
setlocal foldexpr=MyTSIndentFoldExpr()
function! MyTSIndentFoldExpr()
if (getline(v:lnum)=~'^$')
return -1
endif
let ind = TSIndent(getline(v:lnum))
let indNext = TSIndent(getline(v:lnum+1))
return (ind'.(indNext)) : ind
endfunction
setlocal foldtext=MyFoldText()
function! MyFoldText()
let line = getline(v:foldstart)
" Foldtext ignores tabstop and shows tabs as one space,
" so convert tabs to 'tabstop' spaces so text lines up
let ts = repeat(' ',&tabstop)
let line = substitute(line, '\t', ts, 'g')
let numLines = v:foldend - v:foldstart + 1
return line.' ['.numLines.' lines]'
endfunction