I have a file, called WrongFileTypeDetection.R, containing the following text:
# This file is sometimes wrongly detected as a conf file
I also have two versions of _vimrc, that I would have thought to be absolutely identical. However, when I use the first version, the above file is incorrectly detected as a "conf" file, even though I've specifically asked for all files ending with .R to be set to filetype=r. When I change to the second version (moving "syntax on" behind the augroup definition), detection works correctly again. Note that this is the only configuration I have (I moved away my standard vimrc while debugging this).
First version:
syntax on
augroup filetypedetect
autocmd! BufRead,BufNewFile *.r,*.R setfiletype r
augroup END
Second version:
augroup filetypedetect
autocmd! BufRead,BufNewFile *.r,*.R setfiletype r
augroup END
syntax on
It seems that vimrc is very sensitive to the particular ordering of the two files. Why would this be, considering that one of the lines is an autocommand that will be run much later anyway? Is this a bug in Vim or is this a feature that I'm just not understanding?