Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3976190
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:46:30+00:00 2026-05-20T04:46:30+00:00

I have a file, called WrongFileTypeDetection.R, containing the following text: # This file is

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:46:31+00:00Added an answer on May 20, 2026 at 4:46 am

    The simple answer to your problem is that these lines shouldn’t be in your vimrc at all. The officially supported way to handle this is create a filetype.vim file in your .vim directory containing the following:

    " my filetype file
    if exists("did_load_filetypes")
      finish
    endif
    
    augroup filetypedetect
      au! BufRead,BufNewFile *.r setfiletype r
    augroup END
    

    As for why your code is behaving how it does, it’s actually quite a bit more complicated than @too much php’s answer implies.

    In the first version of your vimrc, filetype detection is initialised by your syntax on line. This works by setting up an autocmd to fire when a file with a .r extension is opened, and this autocmd calls the function s:FTr() in filetype.vim.

    However, your autocmd! line overwrites this existing autocmd1, so the s:FTr() function never runs2. Your autocmd then fires, but it doesn’t set the filetype, because the setfiletype command thinks that the filetype has already been set3.

    Then, because the filetype is still not actually set, Vim attempts to assign one based on the contents of the file, and ends up assigning it to the conf type4.

    The best reference for all this is :help filetype. And specifically in your case :help new-filetype and :help remove-filetype. The :verbose command is also very handy for figuring out which settings have been set by what script.

    1: Because of the !. If you were to remove this !, then you would find the filetype being set correctly. This is not the correct solution, though, because then you will be allowing the file to be set to one type (and applying all the settings for that filetype) and then changing it to another. If the second filetype doesn’t overwrite all these settings, some may remain, which might not be what you want.

    2: Try running :set autocmd BufRead *.r when you are using the two different vimrc files. Note the difference in the output given.

    3: See :help setfiletype. Note that if you change the line setfiletype r into set ft=r in the first version of your vimrc, the filetype will be set to r. However, see footnote 1 for why this is not the best solution.

    4: …in a line of code which is commented: “check this last, it’s just guessing”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to work this out. In my project, i have a file called
I have the following style in an external CSS file called first.css table {
On the SVN server, there is a file called config.conf . I have a
I have a file called header.txt I want this file to be prepended (first
I have a file called nochart.png in /drawable . How can I set this
I have a file called main.py and a file called classes.py main.py contains the
I have a file called hellowf.cs class MyFirstApp { static void Main() { System.Windows.Forms.MessageBox.Show(Hello,
Let's say I have a file called test.txt within the package com.test.io within my
For example, suppose I have a batch file called 'test.cmd' and it simply contains:
I have a settings file in my Winforms application called Settings.settings with a partial

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.