1 " Vim support file to detect file types in scripts
3 " Maintainer: Bram Moolenaar <Bram@vim.org>
4 " Last change: 2001 May 03
6 " This file is called by an autocommand for every file that has just been
7 " loaded into a buffer. It checks if the type of file can be recognized by
8 " the file contents. The autocommand is in $VIMRUNTIME/filetype.vim.
11 " Load the user defined scripts file first
12 " Only do this when the FileType autocommand has not been triggered yet
13 if !did_filetype() && exists("myscriptsfile") && file_readable(expand(myscriptsfile))
14 execute "source " . myscriptsfile
17 " Only do this when the FileType autocommand has not been triggered yet
20 " Line continuation is used here, remove 'C' from 'cpoptions'
21 let scr_cpo_save = &cpo
24 " Bourne-like shell scripts: sh ksh bash bash2
25 if getline(1) =~ '^#!.*[/\\]\(bash\|bash2\|ksh\|sh\)\>'
26 call SetFileTypeSH(getline(1)) " defined in filetype.vim
28 " csh and tcsh scripts
29 elseif getline(1) =~ '^#!.*[/\\]t\=csh\>'
33 elseif getline(1) =~ '^#!.*[/\\]zsh\>'
34 \ || getline(1) =~ '^#compdef\>'
35 \ || getline(1) =~ '^#autoload\>'
39 elseif getline(1) =~ '^#!.*[/\\]\(tclsh\|wish\|expectk\|itclsh\|itkwish\)\>'
43 elseif getline(1) =~ '^From [a-zA-Z][a-zA-Z_0-9\.=-]*\(@[^ ]*\)\= .*[12][09]\d\d$'
47 elseif getline(1) =~ '^#!.*[/\\]expect\>'
51 elseif getline(1) =~ '^#!.*[/\\]gnuplot\>'
55 elseif getline(1) =~ '^#!.*[/\\][^/\\]*make\>'
59 elseif getline(1) =~ '^#!.*[/\\][^/\\]*perl[^/\\]*\>'
63 elseif getline(1) =~ '^#!.*[/\\][^/\\]*python[^/\\]*\>'
67 elseif getline(1) =~ '^#!.*[/\\][^/\\]*ruby[^/\\]*\>'
71 elseif getline(1) =~ '^#!.*[/\\]bc\>'
75 elseif getline(1) =~ '^#!.*sed\>'
78 " Vim scripts (must have '" vim' as the first line to trigger this)
79 elseif getline(1) =~ '^" *[vV]im$'
83 " - "diff" in first line (context diff)
84 " - "Only in " in first line
85 " - "--- " in first line and "+++ " in second line (unified diff).
86 " - "*** " in first line and "--- " in second line (context diff).
87 " - "# It was generated by makepatch " in the second line (makepatch diff).
88 " - "Index: <filename>" in the first line (CVS file)
89 elseif getline(1) =~ '^diff\>' || getline(1) =~ '^Only in '
90 \ || (getline(1) =~ '^--- ' && getline(2) =~ '^+++ ')
91 \ || (getline(1) =~ '^\*\*\* ' && getline(2) =~ '^--- ')
92 \ || getline(1) =~ '^\d\+\(,\d\+\)\=[cda]\d\+\>'
93 \ || getline(2) =~ '^# It was generated by makepatch '
94 \ || getline(1) =~ '^Index:\s\+\f\+$'
95 \ || getline(1) =~ '^==== //\f\+#\d\+'
98 " PostScript Files (must have %!PS as the first line, like a2ps output)
99 elseif getline(1) =~ '^%![ \t]*PS'
103 elseif getline(1) =~ '^#!.*awk\>'
106 " M4 scripts: Guess there is a line that starts with "dnl".
107 elseif getline(1) =~ '^\s*dnl\>'
108 \ || getline(2) =~ '^\s*dnl\>'
109 \ || getline(3) =~ '^\s*dnl\>'
110 \ || getline(4) =~ '^\s*dnl\>'
111 \ || getline(5) =~ '^\s*dnl\>'
115 elseif $TERM == "amiga"
116 \ && (getline(1) =~ "^;" || getline(1) =~ '^\.[bB][rR][aA]')
119 " SiCAD scripts (must have procn or procd as the first line to trigger this)
120 elseif getline(1) =~ '^ *[pP][rR][oO][cC][nNdD] *$'
123 " Purify log files start with "**** Purify"
124 elseif getline(1) =~ '^\*\*\*\* Purify'
128 elseif getline(1) =~ '<?\s*xml.*?>'
132 elseif getline(1) =~ '^\x\{7}: \x\{2} \=\x\{2} \=\x\{2} \=\x\{2} '
136 elseif getline(1) =~ '^RCS file:' || getline(2) =~ '^RCS file:'
140 elseif getline(2) =~ '^CVS:'
144 elseif getline(1) =~ '^SNNS network definition file'
146 elseif getline(1) =~ '^SNNS pattern definition file'
148 elseif getline(1) =~ '^SNNS result file'
152 elseif getline(1) =~ '^%.\{-}[Vv]irata'
153 \ || getline(2) =~ '^%.\{-}[Vv]irata'
154 \ || getline(3) =~ '^%.\{-}[Vv]irata'
155 \ || getline(4) =~ '^%.\{-}[Vv]irata'
156 \ || getline(5) =~ '^%.\{-}[Vv]irata'
159 " Website MetaLanguage
160 elseif getline(1) =~ '^#!.*wml.*'
164 elseif getline(1) =~ '^execve('
168 elseif getline(1) =~ '^\* $$ JOB\>' || getline(1) =~ '^// *JOB\>'
172 elseif getline(4) =~ 'K & K Associates' || getline(2) =~ 'TAK 2000'
174 elseif getline(3) =~ 'S Y S T E M S I M P R O V E D '
176 elseif getline(6) =~ 'Run Date: '
178 elseif getline(9) =~ 'Node File 1'
182 elseif getline(1) =~ '\($ORIGIN\|$TTL\|IN\s*SOA\)'
183 \ || getline(2) =~ '\($ORIGIN\|$TTL\|IN\s*SOA\)'
184 \ || getline(1).getline(2).getline(3).getline(4) =~ 'BIND.*named'
187 " Generic configuration file (check this last, it's just guessing!)
188 elseif getline(1) =~ '^#' || getline(2) =~ '^#' || getline(3) =~ '^#'
189 \ || getline(4) =~ '^#' || getline(5) =~ '^#'
194 " Restore 'cpoptions'
195 let &cpo = scr_cpo_save
198 endif " !did_filetype()
200 " vim: ts=8 tw=0 sts=0