Max Dyckhoff wrote:
I am having some issues with filetype detection stuff. Here is what I am
doing, so far as I can see I am doing exactly what it says in the help.
1. I am on Windows, my runtimepath is
~/vimfiles,C:\Program Files\Vim/vimfiles,c:\Progam Files\Vim\vim70,
C:\Program Files\Vim/vimfiles/after,~/vimfiles/after
The folder ~/vimfiles does not exist.
It only needs to exist if there is something in it; and anything in it
is a customization put there by you (the user). Create it (and any
subdirectories) if and when you need to define user-specific
customizations by means of scripts.
2. I have ":filetype plugin indent on" set in my vimrc file.
3. I place a file called wibble.vim in c:\Program
Files\Vim/vimfiles/ftdetect which contains the following:
if exists("did_load_filetypes")
finish
endif
augroup filetypedetect
au! BufRead,BufNewFile *.wibble setfiletype wibblewobble
augroup END
See ":help ftdetect". The "augroup" statements are also not necessary.
The variable "did_load_filetypes" is set to 1 by
$VIMRUNTIME/filetype.vim (at line 10 in the version for Vim 7.0, lat
change May 02). Your script is sourced from line 2166 of the same file,
i.e., much later.
4. I open a file called foo.wibble and do :set filetype, it returns
"filetype=". If I comment out the first three lines of wibble.vim
(namely the check on did_load_filetypes) then it works fine.
So, am I right in not including the did_load_filetypes check (which
:help ftdetect says you should have), or am I doing something wrong
elsewhere?
Cheers!
Max
It's not a bug, it's a feature.
As mentioned under ":help ftdetect" (in the NOTE at line 178 of
filetype.txt for Vim 7.0, last change 2006 Apr 28), your
$VIM/ftdetect/wibble.vim (or, maybe better, wibblewobble.vim) should
only contain the single line
au BufRead,BufNewFile *.wibble setlocal filetype=wibblewobble
("set" in the help is a typo, it would change not only the local value,
which is what you want to do, but also the global default, which you
probably don't want to change). Or you could replace "setlocal
filetype=" by "setf " if it need only be done for files with no
"standard" filetype. (AFAIK, Vim sets no particular 'filetype' for
*.wibble unless, maybe, the contents of the file -- such as a first line
starting with #! -- are recognizable as some specific filetype.)
Then you will probably want to write one or more of the following
scripts (else the filetype detection is rather pointless):
$VIM/vimfiles/ftplugin/wibblewobble.vim
what to do (in general) when opening a file with 'filetype' set to
wibblewobble
$VIM/vimfiles/syntax/wibblewobble.vim
how to colour the data in a file with 'syntax' set to wibblewobble
(which is the default syntax which Vim would automatically set if
'filetype' is set to wibblewobble).
$VIM/vimfiles/indent/wibblewobble.vim
how to auto-indent the code in a file whose 'filetype' is wibblewobble
NOTE: $VIM/vimfiles/ and its subdirectories are for scripts to be used
"system-wide", i.e., by any user who uses Vim (under any login name) on
your system. To restrict the scripts to a single user, replace
$VIM/vimfiles/ by ~/vimfiles/ (on Windows) or by ~/.vim/ (on Unix). If
the directories don't exist, create them.
Best regards,
Tony.