Search code examples
vimlatexneovim

Creating a permanent fold in vim/neovim


I'm using nvim to write up LaTeX documents and would like to be able to fold my 200 line preamble in such a way that if I close and reopen the file, the preamble will still be folded. Is there a way to do this?


Solution

  • These commands will start tex files with all folds engaged:

    augroup tex
        autocmd!
        autocmd FileType tex setlocal foldmethod=marker
        " start out with everything folded away
        autocmd FileType tex setlocal foldlevel=0
        autocmd FileType tex setlocal foldlevelstart=0
    augroup END
    

    So if you use a marker (default {{{ and }}}) around your preamble, this will do the trick.