2

I am new to Vim so I apologize if the answer to this questions is too obvious. I wanted to try Vim-LaTeX, and I like it so far after a couple of days using it.


This is the problem that I have:

I cannot find a way to configure my .vimrc file for custom folding options. As of now, every time I open a TeX file, my preamble, sections, and most of the environments are folded. This can be very annoying, especially when I want to look through code of a large files. Based on that, I have a couple of questions that I will list below.

  • Pressig za in normal mode will unfold the line I am on, and \rf will refresh folding of the entire document. Is there a command that will unfold the whole document?
  • How can I configure .vimrc or any other file so that I completely turn off folding for all TeX documents?
  • How can I customize Vim to fold only what I want? As of right now, I would only prefer to fold the preamble in all my TeX files.

1 Answer 1

3

From :help fold:

zR Open all folds. This sets 'foldlevel' to highest fold level.

From :help 'foldlevelstart':

'foldlevelstart' 'fdls'   number (default: -1)
      global
      {not available when compiled without the |+folding|
      feature}
  Sets 'foldlevel' when starting to edit another buffer in a window.
  Useful to always start editing with all folds closed (value zero),
  some folds closed (one) or no folds closed (99).

So you can add the following to your .vimrc:

set foldlevelstart=99

From :help fold-methods:

There are six methods to select folds:
manual        manually define folds
indent        more indent means a higher fold level
expr          specify an expression to define folds
syntax        folds defined by syntax highlighting
diff          folds for unchanged text
marker        folds defined by markers in the text

So you'll have to investigate the expr method

A word of advice for new vim users about plugins

From personal experience, when I was new to vim I started by installing a lot of plugins very early on. This turned out to be a (common) mistake since when beginning to learn vim, plugins can lead to you not learning a lot of vim's default features. In the end I went through my .vimrc and commented out everything I didn't understand (which was nearly all of it) and then only added each setting/plugin back after researching and understanding what it was doing. This helped me a lot. To be clear I'm not arguing that plugins are bad! I use many of them now, I'm suggesting that plugins can be make it harder to learn vim well at the start.

2
  • Thank you so much for your answer! Also, I agree with your advice completely. I've been using Vim for about a week now, and so far my .vimrc file only has whatever was necessary for Vim-LaTeX and I added relative number lines and English spellcheck.
    – Vladimir
    Jun 26, 2021 at 17:47
  • 2
    @Vladimir I'm glad it helped, I've been using vim for a couple of years now and am still learning new things all the time. A couple of great sites with video tutorials are derekwyatt.org/vim/tutorials/index.html and vimcasts.org
    – mattb
    Jun 26, 2021 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.