Last active
March 20, 2017 04:31
-
-
Save manasthakur/cda8d52ed0ab11aa2b43d19be0e8b2d0 to your computer and use it in GitHub Desktop.
Expression-based folding for latex files in vim
This file contains 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! 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