# Scons files not recognised as Python but as conf

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?

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
finish
endif
augroup filetypedetect
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


https://bitbucket.org/plunket/dotfiles/src/1dc45bcec068220b7df2079b9c1e3b07fd76048f/vim/ftdetect/scons.vim?at=master&fileviewer=file-view-default

• 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 Mar 13 '18 at 17:40
• It's less typing and more modular, which are preferences for me! ;-) – dash-tom-bang Mar 13 '18 at 17:44