1

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?

  • 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 9: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

Your Answer

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

Browse other questions tagged or ask your own question.