Skip to content

Instantly share code, notes, and snippets.

@manasthakur
Last active March 20, 2017 04:31
Show Gist options
  • Save manasthakur/cda8d52ed0ab11aa2b43d19be0e8b2d0 to your computer and use it in GitHub Desktop.
Save manasthakur/cda8d52ed0ab11aa2b43d19be0e8b2d0 to your computer and use it in GitHub Desktop.
Expression-based folding for latex files in vim
function! MyFoldLevel(lnum)
let cur_line = getline(a:lnum)
" Fold sections at level 1
if cur_line =~ '^\s*\\section'
return '>1'
endif
" Fold subsections at level 2
if cur_line =~ '^\s*\\subsection'
return '>2'
endif
" Fold subsubsections at level 3
if cur_line =~ '^\s*\\subsubsection'
return '>3'
endif
" Fold following environments
let fold_envs = ['figure', 'algorithm', 'frame']
let envs = '\(' . join(fold_envs, '\|') . '\)'
if cur_line =~ '^\s*\\begin{' . envs
return 'a1'
endif
if cur_line =~ '^\s*\\end{' . envs
return 's1'
endif
return '='
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment