2

I've added the following lines to my .vimrc after reading about folding the other day (taken from vim.wikia.com):

autocmd Syntax html,python,tex setlocal foldmethod=indent
autocmd Syntax html,python,tex normal zR

I wanted indented folds enabled, but to be open when I first open a file. However, when I open a python file all the folds are closed, and when I open a .tex file all the folds are open.

Does anyone know what the problem is here?

statox
  • 49,782
  • 19
  • 148
  • 225
thosphor
  • 121
  • 2
  • 2
    Seems to work for me for Python files when I add those two lines. There is probably another setting, autocommand, or plugin in your vimrc that is causing the behaviour. Try following the steps in how do I debug my vimrc file? to find out what it is. Also see How to create a Minimal, Complete, and Verifiable example? – Martin Tournoij Aug 26 '16 at 09:52
  • @Carpetsmoker I don't have any plugins installed, I'll try commenting out everything in my vimrc and seeing if that fixes it. – thosphor Aug 26 '16 at 10:04
  • @Carpetsmoker I've commented out everything except those two lines and now I get E490: No fold found where previously it was being folded. With just filetype on and filetype indent on, still no folding (and that error). But as soon as I add filetype plugin on the problem returns. – thosphor Aug 26 '16 at 10:11
  • 1
    I suspect that changing Syntax to Filetype will make it work? This is probably due to the loading order of things... – Martin Tournoij Aug 26 '16 at 14:10
  • If changing to Filetype doesn't help, try putting both commands in a single autocmd (or better, in ftplugins): autocmd Filetype html,python,tex setlocal foldmethod=indent | normal zR. This is just a hunch, but I don't know if Vim offers any guarantees about what order autocmds will be triggered in. – Rich Aug 26 '16 at 14:57
  • @Rich According to :help :autocmd "in the order in which they were given". This is also repeated later: "Vim executes all matching autocommands in the order that you specify them". – Martin Tournoij Aug 26 '16 at 15:18
  • @Carpetsmoker Thanks for the correction. I skimmed the help before writing that comment, but somehow missed both of those. – Rich Aug 30 '16 at 15:34
  • @Carpetsmoker Changing Syntax to Filetype worked. If you want to put that as an answer I can accept it. – thosphor Sep 05 '16 at 13:54

0 Answers0