Re: filetype question
- * Bram Moolenaar (Bram@...) wrote:
>This is great, and thanks for pointing to the "setfiletype" command.
> Alan Schmitt wrote:
> > I just noticed that when I edit a .txt file, the file type is not set to
> > "text". Looking at the filetype.vim file, this seems correct (no rule
> > sets the filetype as "text"). There are however some interesting rules
> > there, which I would like to run first (for instance to view robots.txt
> > using the correct "robots" filetype).
> > Looking at the docs for new-filetype, it was not immediately clear that
> > I was in the "A" case which starts by saying: "If you want to overrule
> > all default file type checks." In my case I don't even want to overrule
> > a default type check, I want to extend it. I found out how to do it by
> > looking at the last example (about pascal).
> > So I suggest the following two changes to the documentation:
> > - first say at the beginning "If you want to overrule some default file
> > type checks, or extend them".
> > - give an example such as:
> > To set all .txt files as text, unless they have already been detected
> > to be another file type by the default checks:
> > au BufRead,BufNewFile *.txt if &ft == '' | set ft=text | endif
> This is indeed hidden inside the "A" alternative. I think it's better
> to make a separate alternative for it, so that it's easy to find:
> B. If you want to detect your file after the default file type checks.
> This works like A above, but instead of setting 'filetype' unconditionally
> use ":setfiletype". This will only set 'filetype' if no file type was
> detected yet. Example: >
> au BufRead,BufNewFile *.txt setfiletype text
> You can also use the already detected file type in your command. For
> example, to use the file type "mypascal" when "pascal" has been detected: >
> au BufRead,BufNewFile * if &ft == 'pascal' | set ft=mypascal
> | endif
The hacker: someone who figured things out and made something cool happen.