1

From :h new-filetype :

A. If you want to overrule all default file type checks.
   This works by writing one file for each filetype.  The disadvantage is that
   means there can be many files.  The advantage is that you can simply drop
   this file in the right directory to make it work.

I'm having trouble understanding this paragraph for a long time, what does one file for each filetype mean here ? Do i need to create a file in ftdetect for every filetype that I want to overrule ?

AFAIK, if i write .vim/ftdetect/mine.vim like this :

autocmd BufRead,BufNewFile *.vim set filetype=vim_test
autocmd BufRead,BufNewFile *.h set filetype=h_test
autocmd BufRead,BufNewFile *.cpp set filetype=cpp_test

It affects all *.vim, *.h, *.cpp, it seems to me that one mine.vim in ftdetect is sufficient for all filetypes that i want to overrule. What am i missing?

2

What you are missing is the (highly subjective) organization.

Ideally each of the lines would be in separate files, which makes debugging easier and helps you to group things together. In other words, do you immediately know what filetypes you overrule by looking at the name ftdetect/mine.vim?

What about ftdetect/vim_test.vim and ftdetect/h_test.vim?

As you have noted, however, it isn’t strictly necessary.

| improve this answer | |
  • Thanks for your answer. I think verbose set filetype gives precise line where filetype is set in mine.vim, i don't think this kind of organization make sense. – dedowsdi Jul 26 '19 at 23:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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