So recently I noticed my autocmd FileType python setlocal foldmethod=indent is not working anymore. The version for my vim is 8.2

When I open a python file everything is working fine except the folding and setlocal foldmethod? returns foldmethod=manual.

verbose set ft? returns

        Last set from /usr/share/vim/vim82/filetype.vim line 1364    

Which from this autocmd

au BufNewFile,BufRead *.py,*.pyw,.pythonstartup,.pythonrc  setf python

verbose setlocal foldmethod? returns just foldmethod=manual and not where it is last set.

When I set verbose=9 I do find the autocmd triggered and nothing else that sets the foldmethod.

Executing FileType Autocommands for "python"
autocommand setlocal foldmethod=indent

Anything else I can check?

edit: I found the culprit

The problem was a faulty autocmd in my vimrc.

let g:my_coc_file_types = ['vim', 'sh', 'python', 'tex']

autocmd FileType * if index(g:my_coc_file_types, &filetype) == -1 | let b:coc_enabled=0

that has to end with | endif

So the why and the how? Is that still an interesting question to be answered?

  • 3
    Welcome to Vi and Vim! Is it possible that you have plug-ins to manage sessions or views and that the setting you're getting is being restored from a view? They save option values by default... And also save folds (in case of manual folds) so that might be an area where there might be interference...
    – filbranden
    Jul 8 at 23:15
  • 1
    In addition to @filbranden's suggestion I would do a quick search of your runtimepath for python ftplugins (thought that should show up in :verbose) and also try :debug edit some.py from which you can step through every bit of code that runs. Lastly, it might be worth just dropping your setlocal in ~/.vim/after/ftplugin/python.vim—if that doesn't solve the problem, it's extremely likely to be sessions/views/something similar.
    – D. Ben Knoble
    Jul 9 at 1:48

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.