I have the following autocmd:

:autocmd FileType python syntax off 

Yet when I open a python file it does nothing. I literally have to run :set ft=python for this to trigger. Does the FileType python not run when reading a buffer? What is the usual way to apply changes at the file-specific level?

  • Sure this isn't a duplicate of Autocmds for particular filetypes (which I answered)? – B Layer Jun 12 '20 at 0:14
  • Er, how are you sure the file is a python file (file suffix, i assume)? Are you using :filetype on (or one of its variants that include ftplugins or indent scripts)? Ftplugins are generally a better way to handle this. But filetype event is triggered when filetype is set. The command i gave turns on the detection mechanism which causes filetypes to be set when editing files (thereby triggering the event...) – D. Ben Knoble Jun 12 '20 at 3:04
  • @BLayer not really -- the other is a great answer (which I've accepted) but here I'm more curious about why I have to 're-run' :set ft=python for it to trigger. – David542 Jun 12 '20 at 3:42
  • @D.BenKnoble yea I have :filetype on in my vimrc. – David542 Jun 12 '20 at 3:43
  • 1
    1. Always use augroup; 2. Do not change global settings from buffer-specific autocommands. Normally that makes no sense, so you should rewrite your example to do something more sensible. 3. Make sure you've read :h autocmd-nested – Matt Jun 12 '20 at 3:58

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.