Vim can also determine file types by checking their contents (for example, if the first line contains shebang), here is a quote from the help filetype.txt :
If your file type can only be detected by checking the contents of the file
Create your working user folder. Usually you use the first element of the runtimepath option. Example for Unix:
:!mkdir ~/.vim
Create a vim script file for this. Example:
if did_filetype() " filetype already set.. finish " ..don't do these checks endif if getline(1) =~ '^#!.*\<mine\>' setfiletype mine elseif getline(1) =~? '\<drawing\>' setfiletype drawing endif
See $ VIMRUNTIME / scripts.vim for more examples. Write this file as "scripts.vim" in the user directory. For example, for Unix:
:w ~/.vim/scripts.vim
Detection will work immediately, there is no need to restart Vim.
Your scripts.vim file is loaded prior to checking for default file types, which means that your rules will override the default rules in $ VIMRUNTIME / scripts.vim.
Matteo Riva Apr 05 '10 at 8:02 2010-04-05 08:02
source share