Alexey I. Froloff wrote:
filetype.vim looks like:

augroup filetypedetect

...

" Generic configuration file (check this last, it's just guessing!)
au BufNewFile,BufRead,StdinReadPost *
        \ ... some files are being setf'ed to "conf"

" Use the plugin-filetype checks last, they may overrule any of the previously
" detected filetypes.
runtime! ftdetect/*.vim

augroup END


So, if Vim sets filetype to "conf", it is not possible to use
:setf from ftdetect/*.vim, because of "but only if not done yet
in a sequence of (nested) autocommands." setf feature.

Solution is simple - source ftdetect/*.vim before "conf"
fallback.


1. You should never create, delete or modify any file in the $VIMRUNTIME directory tree, because any upgrade or bugfix may at any time silently overwrite anything there, and a point release (such as 7.1) will certainly re-create everything there from scratch (under another name, such as .../vim/vim71/ instead of .../vim/vim70/). User customizations to Vim should go in the _other_ directory trees mentioned in the 'runtimepath' option, usually as follows:

        ~/.vim/
        single-user full-fledged scripts on Unix

        ~/vimfiles/
        single-user full-fledged scripts on Windows

        $VIM/vimfiles/
        system-wide full-fledged scripts on all platforms

        $VIM/vimfiles/after/
        small system-wide tweaks to scripts under $VIMRUNTIME or any
        of the above

        ~/vimfiles/after/
        on Windows, small single-user tweaks to any of the above

        ~/.vim/after/
        on Unix, small single-user tweaks to any of the above.

2. The files detected as "conf" are the following:

auto.master

anything not yet detected which has a # in column 1 of one or more of the first 5 lines, unless the filepathname has a match in g:ft_ignore_pat (this is done after all other tests except ftdetect/*.vim and any filetype.vim in an |after-directory| )

3. If you know that a filetype may already have been assigned and you're dead sure you want to change it, use ":set filetype=foobar" rather than ":setfiletype foobar". You may even let Vim do part of the detection for you by using

        if &filetype == "conf"
                if ...
                        set filetype=foobar
                endif
        endif

Using "set filetype=something" rather than "setfiletype something" in ftdetect/*vim scripts is what is explicitly shown in the example in paragraph 2 under ":help ftdetect". At the end of the same help topic, just above paragraph B, |:setfiletype| is mentioned with the words: "if you want to keep a previously detected filetype". I'm not inventing anything. If you want to _override_ a previously detected filetype instead, don't use it.

4. You may also set g:ft_ignore_pat to force non-detection of some files. The default (which will be set by $VIMRUNTIME/filetype.vim the first time it is run, unless the user has already set something before) is '\.\(Z\|gz\|bz2\|zip\|tgz\)$' which means "anything ending in one of .Z .gz .bz2 .zip or .tgz". (see ":help filetype-ignore").


Best regards,
Tony.

Reply via email to