Skip to content

Instantly share code, notes, and snippets.

@manasthakur
Last active Mar 20, 2017
Embed
What would you like to do?
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