I included the following custom fold in .vimrc

let g:Tex_FoldedEnvironments = ',frame,block,algorithm'

I have perfect folding of frame and block, but not for algorithm. It folds all the lines of algorithm except the last line \end{algorithm}.

The following open code: enter image description here

looks like this: enter image description here

How can I correct this?

FYI, my full .vimrc is the following:

execute pathogen#infect()

" from vim-latex installation manual
filetype plugin on
set shellslash
filetype indent on
let g:tex_flavor='latex'
let g:Tex_AdvancedMath = 1  " provides <Alt> mappings, overrides ASCII char insertion
" set winaltkeys=no " if there conflicts with menubar shortcuts

"compilation rules
let g:tex_flavor='latex'
let g:Tex_DefaultTargetFormat='pdf'
" let g:Tex_CompileRule_pdf = 'pdflatex -interaction=batchmode $*'
let g:Tex_CompileRule_pdf = 'pdflatex -interaction=nonstopmode $*'

" Folding keyworkds
let g:Tex_FoldedEnvironments = ',frame,block,algorithm'

" mapping compile to w and W
map :ww :w<cr><leader>ll<cr><leader>lv
map :WW :ww

" mapping Caps H,J,K,L to navigation
map J j
" map K k
" map L l
" map H h

"line numbering
set number

"Spell check
set spell

1 Answer 1


By design vim-latex with let g:Tex_FoldedEnvironments='foo' will fold any environment beginning foo, such that the environments foo, foobar, and foobaz will all be folded (see 8.2.2 Tex_FoldedEnvironments).

Unfortunately vim-latex appears not be checking that the beginning and ending environment match, and so is finding a \begin{algorithm and after that the first time it finds something beginning \end{algorithm is the \end{algorithmic} line.

The same advice given in 8.2.2 Tex_FoldedEnvironments to avoid let g:Tex_FoldedEnvironments='foo' folding the foo and foobar environments works here: let g:Tex_FoldedEnvironments=',algorithm}' will only fold algorithm and not algorithmic.

While it might also seem like it should work let g:Tex_FoldedEnvironments=',algorithm,algorithmic' folds algorithmic correctly but then matches \begin{algorithm} with \end{algorithmic} even though it's already folded algorithmic.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .