Neovim assigns a file type of "conf" to SConscruct and SConscript files -- aka the scons configuration scripts. This is wrong. It should be Python.

I tried adding: au BufNewFile,BufRead SCons* setf python to my ~/.config/nvim/init.vim yet the file type remains set at "conf".

I did try it on vim and it worked fine.

What am I doing wrong?


2 Answers 2


There are a couple of problems here.

Firstly, you are using the :setfiletype command, which only sets the 'filetype' if it has not already been set. (See :help :setfiletype.)

If you change your autocommand to set the 'filetype' directly with :set filetype=python, this will result in the python filetype being used, as you desire.

However, this still isn't perfect, because now Vim is first setting the 'filetype' to conf (based on its contents) and then changing it to python, and it's possible that some options are set for conf files that you do not want in python files.

To avoid this, follow the instructions in section C of :help new-filetype to detect this filetype before the installed detection runs by creating a .vim/filetype.vim file with the following contents:

" my filetype file
if exists("did_load_filetypes")
augroup filetypedetect
  autocmd! BufRead,BufNewFile SCons* setfiletype python
augroup END

I'd also note that it's not really a bug that Vim is using a 'filetype' of conf here. Vim's runtime files set a large number of types automatically, but they cannot automatically set the types of all files, now and in the future. This is why the mechanisms described in the documentation linked to above exist: to allow you to add filetype detection for currently unsupported files as necessary.

It is of course, reasonable to suggest that it be added as a feature request: hopefully automatic detection of SCons files will be added in future versions!


Put a file this content into your .vim/ftdetect folder, I name it scons.vim:

autocmd BufRead,BufNewFile SCons{truct,cript} set filetype=python


  • 2
    Note that this will still result in the file first being set to have a type of conf, as I described in my answer. See Section A of :help new-filetype
    – Rich
    Commented Mar 13, 2018 at 17:40
  • It's less typing and more modular, which are preferences for me! ;-) Commented Mar 13, 2018 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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