xref: /vim-8.2.3635/runtime/filetype.vim (revision c0880db6)
1" Vim support file to detect file types
2"
3" Maintainer:	Bram Moolenaar <[email protected]>
4" Last Change:	2009 Dec 24
5
6" Listen very carefully, I will say this only once
7if exists("did_load_filetypes")
8  finish
9endif
10let did_load_filetypes = 1
11
12" Line continuation is used here, remove 'C' from 'cpoptions'
13let s:cpo_save = &cpo
14set cpo&vim
15
16augroup filetypedetect
17
18" Ignored extensions
19if exists("*fnameescape")
20au BufNewFile,BufRead ?\+.orig,?\+.bak,?\+.old,?\+.new,?\+.dpkg-dist,?\+.dpkg-old,?\+.rpmsave,?\+.rpmnew
21	\ exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r"))
22au BufNewFile,BufRead *~
23	\ let s:name = expand("<afile>") |
24	\ let s:short = substitute(s:name, '\~$', '', '') |
25	\ if s:name != s:short && s:short != "" |
26	\   exe "doau filetypedetect BufRead " . fnameescape(s:short) |
27	\ endif |
28	\ unlet! s:name s:short
29au BufNewFile,BufRead ?\+.in
30	\ if expand("<afile>:t") != "configure.in" |
31	\   exe "doau filetypedetect BufRead " . fnameescape(expand("<afile>:r")) |
32	\ endif
33elseif &verbose > 0
34  echomsg "Warning: some filetypes will not be recognized because this version of Vim does not have fnameescape()"
35endif
36
37" Pattern used to match file names which should not be inspected.
38" Currently finds compressed files.
39if !exists("g:ft_ignore_pat")
40  let g:ft_ignore_pat = '\.\(Z\|gz\|bz2\|zip\|tgz\)$'
41endif
42
43" Function used for patterns that end in a star: don't set the filetype if the
44" file name matches ft_ignore_pat.
45func! s:StarSetf(ft)
46  if expand("<amatch>") !~ g:ft_ignore_pat
47    exe 'setf ' . a:ft
48  endif
49endfunc
50
51" Abaqus or Trasys
52au BufNewFile,BufRead *.inp			call s:Check_inp()
53
54func! s:Check_inp()
55  if getline(1) =~ '^\*'
56    setf abaqus
57  else
58    let n = 1
59    if line("$") > 500
60      let nmax = 500
61    else
62      let nmax = line("$")
63    endif
64    while n <= nmax
65      if getline(n) =~? "^header surface data"
66	setf trasys
67	break
68      endif
69      let n = n + 1
70    endwhile
71  endif
72endfunc
73
74" A-A-P recipe
75au BufNewFile,BufRead *.aap			setf aap
76
77" A2ps printing utility
78au BufNewFile,BufRead etc/a2ps.cfg,etc/a2ps/*.cfg,a2psrc,.a2psrc setf a2ps
79
80" ABAB/4
81au BufNewFile,BufRead *.abap			setf abap
82
83" ABC music notation
84au BufNewFile,BufRead *.abc			setf abc
85
86" ABEL
87au BufNewFile,BufRead *.abl			setf abel
88
89" AceDB
90au BufNewFile,BufRead *.wrm			setf acedb
91
92" Ada (83, 9X, 95)
93au BufNewFile,BufRead *.adb,*.ads,*.ada		setf ada
94if has("vms")
95  au BufNewFile,BufRead *.gpr,*.ada_m,*.adc	setf ada
96else
97  au BufNewFile,BufRead *.gpr			setf ada
98endif
99
100" AHDL
101au BufNewFile,BufRead *.tdf			setf ahdl
102
103" AMPL
104au BufNewFile,BufRead *.run			setf ampl
105
106" Ant
107au BufNewFile,BufRead build.xml			setf ant
108
109" Apache style config file
110au BufNewFile,BufRead proftpd.conf*		call s:StarSetf('apachestyle')
111
112" Apache config file
113au BufNewFile,BufRead .htaccess,/etc/httpd/*.conf		 setf apache
114au BufNewFile,BufRead httpd.conf*,srm.conf*,access.conf*,apache.conf*,apache2.conf*,/etc/apache2/*.conf*,/etc/httpd/conf.d/*.conf* call s:StarSetf('apache')
115
116" XA65 MOS6510 cross assembler
117au BufNewFile,BufRead *.a65			setf a65
118
119" Applescript
120au BufNewFile,BufRead *.scpt			setf applescript
121
122" Applix ELF
123au BufNewFile,BufRead *.am
124	\ if expand("<afile>") !~? 'Makefile.am\>' | setf elf | endif
125
126" ALSA configuration
127au BufNewFile,BufRead ~/.asoundrc,/usr/share/alsa/alsa.conf,/etc/asound.conf	setf alsaconf
128
129" Arc Macro Language
130au BufNewFile,BufRead *.aml			setf aml
131
132" Arch Inventory file
133au BufNewFile,BufRead .arch-inventory,=tagging-method	setf arch
134
135" ART*Enterprise (formerly ART-IM)
136au BufNewFile,BufRead *.art			setf art
137
138" ASN.1
139au BufNewFile,BufRead *.asn,*.asn1		setf asn
140
141" Active Server Pages (with Visual Basic Script)
142au BufNewFile,BufRead *.asa
143	\ if exists("g:filetype_asa") |
144	\   exe "setf " . g:filetype_asa |
145	\ else |
146	\   setf aspvbs |
147	\ endif
148
149" Active Server Pages (with Perl or Visual Basic Script)
150au BufNewFile,BufRead *.asp
151	\ if exists("g:filetype_asp") |
152	\   exe "setf " . g:filetype_asp |
153	\ elseif getline(1) . getline(2) . getline(3) =~? "perlscript" |
154	\   setf aspperl |
155	\ else |
156	\   setf aspvbs |
157	\ endif
158
159" Grub (must be before catch *.lst)
160au BufNewFile,BufRead /boot/grub/menu.lst,/boot/grub/grub.conf,/etc/grub.conf	setf grub
161
162" Assembly (all kinds)
163" *.lst is not pure assembly, it has two extra columns (address, byte codes)
164au BufNewFile,BufRead *.asm,*.[sS],*.[aA],*.mac,*.lst	call s:FTasm()
165
166" This function checks for the kind of assembly that is wanted by the user, or
167" can be detected from the first five lines of the file.
168func! s:FTasm()
169  " make sure b:asmsyntax exists
170  if !exists("b:asmsyntax")
171    let b:asmsyntax = ""
172  endif
173
174  if b:asmsyntax == ""
175    call s:FTasmsyntax()
176  endif
177
178  " if b:asmsyntax still isn't set, default to asmsyntax or GNU
179  if b:asmsyntax == ""
180    if exists("g:asmsyntax")
181      let b:asmsyntax = g:asmsyntax
182    else
183      let b:asmsyntax = "asm"
184    endif
185  endif
186
187  exe "setf " . fnameescape(b:asmsyntax)
188endfunc
189
190func! s:FTasmsyntax()
191  " see if file contains any asmsyntax=foo overrides. If so, change
192  " b:asmsyntax appropriately
193  let head = " ".getline(1)." ".getline(2)." ".getline(3)." ".getline(4).
194	\" ".getline(5)." "
195  let match = matchstr(head, '\sasmsyntax=\zs[a-zA-Z0-9]\+\ze\s')
196  if match != ''
197    let b:asmsyntax = match
198  elseif ((head =~? '\.title') || (head =~? '\.ident') || (head =~? '\.macro') || (head =~? '\.subtitle') || (head =~? '\.library'))
199    let b:asmsyntax = "vmasm"
200  endif
201endfunc
202
203" Macro (VAX)
204au BufNewFile,BufRead *.mar			setf vmasm
205
206" Atlas
207au BufNewFile,BufRead *.atl,*.as		setf atlas
208
209" Autoit v3
210au BufNewFile,BufRead *.au3			setf autoit
211
212" Autohotkey
213au BufNewFile,BufRead *.ahk			setf autohotkey
214
215" Automake
216au BufNewFile,BufRead [mM]akefile.am,GNUmakefile.am	setf automake
217
218" Autotest .at files are actually m4
219au BufNewFile,BufRead *.at			setf m4
220
221" Avenue
222au BufNewFile,BufRead *.ave			setf ave
223
224" Awk
225au BufNewFile,BufRead *.awk			setf awk
226
227" B
228au BufNewFile,BufRead *.mch,*.ref,*.imp		setf b
229
230" BASIC or Visual Basic
231au BufNewFile,BufRead *.bas			call s:FTVB("basic")
232
233" Check if one of the first five lines contains "VB_Name".  In that case it is
234" probably a Visual Basic file.  Otherwise it's assumed to be "alt" filetype.
235func! s:FTVB(alt)
236  if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'VB_Name\|Begin VB\.\(Form\|MDIForm\|UserControl\)'
237    setf vb
238  else
239    exe "setf " . a:alt
240  endif
241endfunc
242
243" Visual Basic Script (close to Visual Basic)
244au BufNewFile,BufRead *.vbs,*.dsm,*.ctl		setf vb
245
246" IBasic file (similar to QBasic)
247au BufNewFile,BufRead *.iba,*.ibi		setf ibasic
248
249" FreeBasic file (similar to QBasic)
250au BufNewFile,BufRead *.fb,*.bi			setf freebasic
251
252" Batch file for MSDOS.
253au BufNewFile,BufRead *.bat,*.sys		setf dosbatch
254" *.cmd is close to a Batch file, but on OS/2 Rexx files also use *.cmd.
255au BufNewFile,BufRead *.cmd
256	\ if getline(1) =~ '^/\*' | setf rexx | else | setf dosbatch | endif
257
258" Batch file for 4DOS
259au BufNewFile,BufRead *.btm			call s:FTbtm()
260func! s:FTbtm()
261  if exists("g:dosbatch_syntax_for_btm") && g:dosbatch_syntax_for_btm
262    setf dosbatch
263  else
264    setf btm
265  endif
266endfunc
267
268" BC calculator
269au BufNewFile,BufRead *.bc			setf bc
270
271" BDF font
272au BufNewFile,BufRead *.bdf			setf bdf
273
274" BibTeX bibliography database file
275au BufNewFile,BufRead *.bib			setf bib
276
277" BibTeX Bibliography Style
278au BufNewFile,BufRead *.bst			setf bst
279
280" BIND configuration
281au BufNewFile,BufRead named.conf,rndc.conf	setf named
282
283" BIND zone
284au BufNewFile,BufRead named.root		setf bindzone
285au BufNewFile,BufRead *.db			call s:BindzoneCheck('')
286
287func! s:BindzoneCheck(default)
288  if getline(1).getline(2).getline(3).getline(4) =~ '^; <<>> DiG [0-9.]\+ <<>>\|BIND.*named\|$ORIGIN\|$TTL\|IN\s\+SOA'
289    setf bindzone
290  elseif a:default != ''
291    exe 'setf ' . a:default
292  endif
293endfunc
294
295" Blank
296au BufNewFile,BufRead *.bl			setf blank
297
298" Blkid cache file
299au BufNewFile,BufRead /etc/blkid.tab,/etc/blkid.tab.old   setf xml
300
301" C or lpc
302au BufNewFile,BufRead *.c			call s:FTlpc()
303
304func! s:FTlpc()
305  if exists("g:lpc_syntax_for_c")
306    let lnum = 1
307    while lnum <= 12
308      if getline(lnum) =~# '^\(//\|inherit\|private\|protected\|nosave\|string\|object\|mapping\|mixed\)'
309	setf lpc
310	return
311      endif
312      let lnum = lnum + 1
313    endwhile
314  endif
315  setf c
316endfunc
317
318" Calendar
319au BufNewFile,BufRead calendar			setf calendar
320au BufNewFile,BufRead */.calendar/*,
321	\*/share/calendar/*/calendar.*,*/share/calendar/calendar.*
322	\					call s:StarSetf('calendar')
323
324" C#
325au BufNewFile,BufRead *.cs			setf cs
326
327" Cdrdao TOC
328au BufNewFile,BufRead *.toc			setf cdrtoc
329
330" Cdrdao config
331au BufNewFile,BufRead etc/cdrdao.conf,etc/defaults/cdrdao,etc/default/cdrdao,~/.cdrdao						setf cdrdaoconf
332
333" Cfengine
334au BufNewFile,BufRead cfengine.conf		setf cfengine
335
336" Comshare Dimension Definition Language
337au BufNewFile,BufRead *.cdl			setf cdl
338
339" Conary Recipe
340au BufNewFile,BufRead *.recipe			setf conaryrecipe
341
342" Controllable Regex Mutilator
343au BufNewFile,BufRead *.crm			setf crm
344
345" Cyn++
346au BufNewFile,BufRead *.cyn			setf cynpp
347
348" Cynlib
349" .cc and .cpp files can be C++ or Cynlib.
350au BufNewFile,BufRead *.cc
351	\ if exists("cynlib_syntax_for_cc")|setf cynlib|else|setf cpp|endif
352au BufNewFile,BufRead *.cpp
353	\ if exists("cynlib_syntax_for_cpp")|setf cynlib|else|setf cpp|endif
354
355" C++
356au BufNewFile,BufRead *.cxx,*.c++,*.hh,*.hxx,*.hpp,*.ipp,*.moc,*.tcc,*.inl setf cpp
357if has("fname_case")
358  au BufNewFile,BufRead *.C,*.H setf cpp
359endif
360
361" .h files can be C, Ch C++, ObjC or ObjC++.
362" Set c_syntax_for_h if you want C, ch_syntax_for_h if you want Ch. ObjC is
363" detected automatically.
364au BufNewFile,BufRead *.h			call s:FTheader()
365
366func! s:FTheader()
367  if match(getline(1, min([line("$"), 200])), '^@\(interface\|end\|class\)') > -1
368    setf objc
369  elseif exists("g:c_syntax_for_h")
370    setf c
371  elseif exists("g:ch_syntax_for_h")
372    setf ch
373  else
374    setf cpp
375  endif
376endfunc
377
378" Ch (CHscript)
379au BufNewFile,BufRead *.chf			setf ch
380
381" TLH files are C++ headers generated by Visual C++'s #import from typelibs
382au BufNewFile,BufRead *.tlh			setf cpp
383
384" Cascading Style Sheets
385au BufNewFile,BufRead *.css			setf css
386
387" Century Term Command Scripts (*.cmd too)
388au BufNewFile,BufRead *.con			setf cterm
389
390" Changelog
391au BufNewFile,BufRead changelog.Debian,changelog.dch,NEWS.Debian,NEWS.dch
392					\	setf debchangelog
393
394au BufNewFile,BufRead [cC]hange[lL]og
395	\  if getline(1) =~ '; urgency='
396	\|   setf debchangelog
397	\| else
398	\|   setf changelog
399	\| endif
400
401au BufNewFile,BufRead NEWS
402	\  if getline(1) =~ '; urgency='
403	\|   setf debchangelog
404	\| endif
405
406" CHILL
407au BufNewFile,BufRead *..ch			setf chill
408
409" Changes for WEB and CWEB or CHILL
410au BufNewFile,BufRead *.ch			call s:FTchange()
411
412" This function checks if one of the first ten lines start with a '@'.  In
413" that case it is probably a change file.
414" If the first line starts with # or ! it's probably a ch file.
415" If a line has "main", "include", "//" ir "/*" it's probably ch.
416" Otherwise CHILL is assumed.
417func! s:FTchange()
418  let lnum = 1
419  while lnum <= 10
420    if getline(lnum)[0] == '@'
421      setf change
422      return
423    endif
424    if lnum == 1 && (getline(1)[0] == '#' || getline(1)[0] == '!')
425      setf ch
426      return
427    endif
428    if getline(lnum) =~ "MODULE"
429      setf chill
430      return
431    endif
432    if getline(lnum) =~ 'main\s*(\|#\s*include\|//'
433      setf ch
434      return
435    endif
436    let lnum = lnum + 1
437  endwhile
438  setf chill
439endfunc
440
441" ChordPro
442au BufNewFile,BufRead *.chopro,*.crd,*.cho,*.crdpro,*.chordpro	setf chordpro
443
444" Clean
445au BufNewFile,BufRead *.dcl,*.icl		setf clean
446
447" Clever
448au BufNewFile,BufRead *.eni			setf cl
449
450" Clever or dtd
451au BufNewFile,BufRead *.ent			call s:FTent()
452
453func! s:FTent()
454  " This function checks for valid cl syntax in the first five lines.
455  " Look for either an opening comment, '#', or a block start, '{".
456  " If not found, assume SGML.
457  let lnum = 1
458  while lnum < 6
459    let line = getline(lnum)
460    if line =~ '^\s*[#{]'
461      setf cl
462      return
463    elseif line !~ '^\s*$'
464      " Not a blank line, not a comment, and not a block start,
465      " so doesn't look like valid cl code.
466      break
467    endif
468    let lnum = lnum + 1
469  endw
470  setf dtd
471endfunc
472
473" Clipper (or FoxPro; could also be eviews)
474au BufNewFile,BufRead *.prg
475	\ if exists("g:filetype_prg") |
476	\   exe "setf " . g:filetype_prg |
477	\ else |
478	\   setf clipper |
479	\ endif
480
481" Cmake
482au BufNewFile,BufRead CMakeLists.txt,*.cmake,*.cmake.in		setf cmake
483
484" Cmusrc
485au BufNewFile,BufRead ~/.cmus/{autosave,rc,command-history,*.theme} setf cmusrc
486au BufNewFile,BufRead */cmus/{rc,*.theme}			setf cmusrc
487
488" Cobol
489au BufNewFile,BufRead *.cbl,*.cob,*.lib	setf cobol
490"   cobol or zope form controller python script? (heuristic)
491au BufNewFile,BufRead *.cpy
492	\ if getline(1) =~ '^##' |
493	\   setf python |
494	\ else |
495	\   setf cobol |
496	\ endif
497
498" Coco/R
499au BufNewFile,BufRead *.atg			setf coco
500
501" Cold Fusion
502au BufNewFile,BufRead *.cfm,*.cfi,*.cfc		setf cf
503
504" Configure scripts
505au BufNewFile,BufRead configure.in,configure.ac setf config
506
507" CUDA  Cumpute Unified Device Architecture
508au BufNewFile,BufRead *.cu			setf cuda
509
510" WildPackets EtherPeek Decoder
511au BufNewFile,BufRead *.dcd			setf dcd
512
513" Enlightenment configuration files
514au BufNewFile,BufRead *enlightenment/*.cfg	setf c
515
516" Eterm
517au BufNewFile,BufRead *Eterm/*.cfg		setf eterm
518
519" Lynx config files
520au BufNewFile,BufRead lynx.cfg			setf lynx
521
522" Quake
523au BufNewFile,BufRead *baseq[2-3]/*.cfg,*id1/*.cfg	setf quake
524au BufNewFile,BufRead *quake[1-3]/*.cfg			setf quake
525
526" Quake C
527au BufNewFile,BufRead *.qc			setf c
528
529" Configure files
530au BufNewFile,BufRead *.cfg			setf cfg
531
532" Communicating Sequential Processes
533au BufNewFile,BufRead *.csp,*.fdr		setf csp
534
535" CUPL logic description and simulation
536au BufNewFile,BufRead *.pld			setf cupl
537au BufNewFile,BufRead *.si			setf cuplsim
538
539" Debian Control
540au BufNewFile,BufRead */debian/control		setf debcontrol
541au BufNewFile,BufRead control
542	\  if getline(1) =~ '^Source:'
543	\|   setf debcontrol
544	\| endif
545
546" Debian Sources.list
547au BufNewFile,BufRead /etc/apt/sources.list	setf debsources
548
549" Deny hosts
550au BufNewFile,BufRead denyhosts.conf		setf denyhosts
551
552" ROCKLinux package description
553au BufNewFile,BufRead *.desc			setf desc
554
555" the D language or dtrace
556au BufNewFile,BufRead *.d			call s:DtraceCheck()
557
558func! s:DtraceCheck()
559  let lines = getline(1, min([line("$"), 100]))
560  if match(lines, '^#!\S\+dtrace\|#pragma\s\+D\s\+option\|:\S\{-}:\S\{-}:') > -1
561    setf dtrace
562  else
563    setf d
564  endif
565endfunc
566
567" Desktop files
568au BufNewFile,BufRead *.desktop,.directory	setf desktop
569
570" Dict config
571au BufNewFile,BufRead dict.conf,.dictrc		setf dictconf
572
573" Dictd config
574au BufNewFile,BufRead dictd.conf		setf dictdconf
575
576" Diff files
577au BufNewFile,BufRead *.diff,*.rej,*.patch	setf diff
578
579" Dircolors
580au BufNewFile,BufRead .dir_colors,/etc/DIR_COLORS	setf dircolors
581
582" Diva (with Skill) or InstallShield
583au BufNewFile,BufRead *.rul
584	\ if getline(1).getline(2).getline(3).getline(4).getline(5).getline(6) =~? 'InstallShield' |
585	\   setf ishd |
586	\ else |
587	\   setf diva |
588	\ endif
589
590" DCL (Digital Command Language - vms) or DNS zone file
591au BufNewFile,BufRead *.com			call s:BindzoneCheck('dcl')
592
593" DOT
594au BufNewFile,BufRead *.dot			setf dot
595
596" Dylan - lid files
597au BufNewFile,BufRead *.lid			setf dylanlid
598
599" Dylan - intr files (melange)
600au BufNewFile,BufRead *.intr			setf dylanintr
601
602" Dylan
603au BufNewFile,BufRead *.dylan			setf dylan
604
605" Microsoft Module Definition
606au BufNewFile,BufRead *.def			setf def
607
608" Dracula
609au BufNewFile,BufRead *.drac,*.drc,*lvs,*lpe	setf dracula
610
611" dsl
612au BufNewFile,BufRead *.dsl			setf dsl
613
614" DTD (Document Type Definition for XML)
615au BufNewFile,BufRead *.dtd			setf dtd
616
617" EDIF (*.edf,*.edif,*.edn,*.edo)
618au BufNewFile,BufRead *.ed\(f\|if\|n\|o\)	setf edif
619
620" Embedix Component Description
621au BufNewFile,BufRead *.ecd			setf ecd
622
623" Eiffel or Specman
624au BufNewFile,BufRead *.e,*.E			call s:FTe()
625
626" Elinks configuration
627au BufNewFile,BufRead */etc/elinks.conf,*/.elinks/elinks.conf	setf elinks
628
629func! s:FTe()
630  let n = 1
631  while n < 100 && n < line("$")
632    if getline(n) =~ "^\\s*\\(<'\\|'>\\)\\s*$"
633      setf specman
634      return
635    endif
636    let n = n + 1
637  endwhile
638  setf eiffel
639endfunc
640
641" ERicsson LANGuage; Yaws is erlang too
642au BufNewFile,BufRead *.erl,*.hrl,*.yaws	setf erlang
643
644" Elm Filter Rules file
645au BufNewFile,BufRead filter-rules		setf elmfilt
646
647" ESMTP rc file
648au BufNewFile,BufRead *esmtprc			setf esmtprc
649
650" ESQL-C
651au BufNewFile,BufRead *.ec,*.EC			setf esqlc
652
653" Esterel
654au BufNewFile,BufRead *.strl			setf esterel
655
656" Essbase script
657au BufNewFile,BufRead *.csc			setf csc
658
659" Exim
660au BufNewFile,BufRead exim.conf			setf exim
661
662" Expect
663au BufNewFile,BufRead *.exp			setf expect
664
665" Exports
666au BufNewFile,BufRead exports			setf exports
667
668" Factor
669au BufNewFile,BufRead *.factor			setf factor
670
671" Fetchmail RC file
672au BufNewFile,BufRead .fetchmailrc		setf fetchmail
673
674" FlexWiki - disabled, because it has side effects when a .wiki file
675" is not actually FlexWiki
676"au BufNewFile,BufRead *.wiki			setf flexwiki
677
678" Focus Executable
679au BufNewFile,BufRead *.fex,*.focexec		setf focexec
680
681" Focus Master file (but not for auto.master)
682au BufNewFile,BufRead auto.master		setf conf
683au BufNewFile,BufRead *.mas,*.master		setf master
684
685" Forth
686au BufNewFile,BufRead *.fs,*.ft			setf forth
687
688" Reva Forth
689au BufNewFile,BufRead *.frt			setf reva
690
691" Fortran
692if has("fname_case")
693  au BufNewFile,BufRead *.F,*.FOR,*.FPP,*.FTN,*.F77,*.F90,*.F95	 setf fortran
694endif
695au BufNewFile,BufRead   *.f,*.for,*.fortran,*.fpp,*.ftn,*.f77,*.f90,*.f95  setf fortran
696
697" Framescript
698au BufNewFile,BufRead *.fsl			setf framescript
699
700" FStab
701au BufNewFile,BufRead fstab,mtab		setf fstab
702
703" GDB command files
704au BufNewFile,BufRead .gdbinit			setf gdb
705
706" GDMO
707au BufNewFile,BufRead *.mo,*.gdmo		setf gdmo
708
709" Gedcom
710au BufNewFile,BufRead *.ged,lltxxxxx.txt	setf gedcom
711
712" Git
713autocmd BufNewFile,BufRead *.git/COMMIT_EDITMSG setf gitcommit
714autocmd BufNewFile,BufRead *.git/config,.gitconfig,.gitmodules setf gitconfig
715autocmd BufNewFile,BufRead git-rebase-todo      setf gitrebase
716autocmd BufNewFile,BufRead .msg.[0-9]*
717      \ if getline(1) =~ '^From.*# This line is ignored.$' |
718      \   setf gitsendemail |
719      \ endif
720autocmd BufNewFile,BufRead *.git/**
721      \ if getline(1) =~ '^\x\{40\}\>\|^ref: ' |
722      \   setf git |
723      \ endif
724
725" Gkrellmrc
726au BufNewFile,BufRead gkrellmrc,gkrellmrc_?	setf gkrellmrc
727
728" GP scripts (2.0 and onward)
729au BufNewFile,BufRead *.gp,.gprc		setf gp
730
731" GPG
732au BufNewFile,BufRead */.gnupg/options		setf gpg
733au BufNewFile,BufRead */.gnupg/gpg.conf		setf gpg
734au BufNewFile,BufRead /usr/**/gnupg/options.skel setf gpg
735
736" Gnuplot scripts
737au BufNewFile,BufRead *.gpi			setf gnuplot
738
739" GrADS scripts
740au BufNewFile,BufRead *.gs			setf grads
741
742" Gretl
743au BufNewFile,BufRead *.gretl			setf gretl
744
745" Groovy
746au BufNewFile,BufRead *.groovy			setf groovy
747
748" GNU Server Pages
749au BufNewFile,BufRead *.gsp			setf gsp
750
751" Group file
752au BufNewFile,BufRead /etc/group,/etc/group-,/etc/group.edit,/etc/gshadow,/etc/gshadow-,/etc/gshadow.edit,/var/backups/group.bak,/var/backups/gshadow.bak  setf group
753
754" GTK RC
755au BufNewFile,BufRead .gtkrc,gtkrc		setf gtkrc
756
757" Haml
758au BufNewFile,BufRead *.haml			setf haml
759
760" Hamster Classic | Playground files
761au BufNewFile,BufRead *.hsc,*.hsm		setf hamster
762
763" Haskell
764au BufNewFile,BufRead *.hs			setf haskell
765au BufNewFile,BufRead *.lhs			setf lhaskell
766au BufNewFile,BufRead *.chs			setf chaskell
767
768" Haste
769au BufNewFile,BufRead *.ht			setf haste
770au BufNewFile,BufRead *.htpp			setf hastepreproc
771
772" Hercules
773au BufNewFile,BufRead *.vc,*.ev,*.rs,*.sum,*.errsum	setf hercules
774
775" HEX (Intel)
776au BufNewFile,BufRead *.hex,*.h32		setf hex
777
778" Tilde (must be before HTML)
779au BufNewFile,BufRead *.t.html			setf tilde
780
781" HTML (.shtml and .stm for server side)
782au BufNewFile,BufRead *.html,*.htm,*.shtml,*.stm  call s:FThtml()
783
784" Distinguish between HTML, XHTML and Django
785func! s:FThtml()
786  let n = 1
787  while n < 10 && n < line("$")
788    if getline(n) =~ '\<DTD\s\+XHTML\s'
789      setf xhtml
790      return
791    endif
792    if getline(n) =~ '{%\s*\(extends\|block\)\>'
793      setf htmldjango
794      return
795    endif
796    let n = n + 1
797  endwhile
798  setf html
799endfunc
800
801" HTML with Ruby - eRuby
802au BufNewFile,BufRead *.erb,*.rhtml		setf eruby
803
804" HTML with M4
805au BufNewFile,BufRead *.html.m4			setf htmlm4
806
807" HTML Cheetah template
808au BufNewFile,BufRead *.tmpl			setf htmlcheetah
809
810" Host config
811au BufNewFile,BufRead /etc/host.conf		setf hostconf
812
813" Hosts access
814au BufNewFile,BufRead /etc/hosts.allow,/etc/hosts.deny  setf hostsaccess
815
816" Hyper Builder
817au BufNewFile,BufRead *.hb			setf hb
818
819" Icon
820au BufNewFile,BufRead *.icn			setf icon
821
822" IDL (Interface Description Language)
823au BufNewFile,BufRead *.idl			call s:FTidl()
824
825" Distinguish between standard IDL and MS-IDL
826func! s:FTidl()
827  let n = 1
828  while n < 50 && n < line("$")
829    if getline(n) =~ '^\s*import\s\+"\(unknwn\|objidl\)\.idl"'
830      setf msidl
831      return
832    endif
833    let n = n + 1
834  endwhile
835  setf idl
836endfunc
837
838" Microsoft IDL (Interface Description Language)  Also *.idl
839" MOF = WMI (Windows Management Instrumentation) Managed Object Format
840au BufNewFile,BufRead *.odl,*.mof		setf msidl
841
842" Icewm menu
843au BufNewFile,BufRead */.icewm/menu		setf icemenu
844
845" Indent profile (must come before IDL *.pro!)
846au BufNewFile,BufRead .indent.pro		setf indent
847au BufNewFile,BufRead indent.pro		call s:ProtoCheck('indent')
848
849" IDL (Interactive Data Language)
850au BufNewFile,BufRead *.pro			call s:ProtoCheck('idlang')
851
852" Distinguish between "default" and Cproto prototype file. */
853func! s:ProtoCheck(default)
854  " Cproto files have a comment in the first line and a function prototype in
855  " the second line, it always ends in ";".  Indent files may also have
856  " comments, thus we can't match comments to see the difference.
857  if getline(2) =~ ';$'
858    setf cpp
859  else
860    exe 'setf ' . a:default
861  endif
862endfunc
863
864
865" Indent RC
866au BufNewFile,BufRead indentrc			setf indent
867
868" Inform
869au BufNewFile,BufRead *.inf,*.INF		setf inform
870
871" Initng
872au BufNewFile,BufRead /etc/initng/**/*.i,*.ii	setf initng
873
874" Ipfilter
875au BufNewFile,BufRead ipf.conf,ipf6.conf,ipf.rules	setf ipfilter
876
877" Informix 4GL (source - canonical, include file, I4GL+M4 preproc.)
878au BufNewFile,BufRead *.4gl,*.4gh,*.m4gl	setf fgl
879
880" .INI file for MSDOS
881au BufNewFile,BufRead *.ini			setf dosini
882
883" SysV Inittab
884au BufNewFile,BufRead inittab			setf inittab
885
886" Inno Setup
887au BufNewFile,BufRead *.iss			setf iss
888
889" JAL
890au BufNewFile,BufRead *.jal,*.JAL		setf jal
891
892" Jam
893au BufNewFile,BufRead *.jpl,*.jpr		setf jam
894
895" Java
896au BufNewFile,BufRead *.java,*.jav		setf java
897
898" JavaCC
899au BufNewFile,BufRead *.jj,*.jjt		setf javacc
900
901" JavaScript, ECMAScript
902au BufNewFile,BufRead *.js,*.javascript,*.es,*.jsx	setf javascript
903
904" Java Server Pages
905au BufNewFile,BufRead *.jsp			setf jsp
906
907" Java Properties resource file (note: doesn't catch font.properties.pl)
908au BufNewFile,BufRead *.properties,*.properties_??,*.properties_??_??	setf jproperties
909au BufNewFile,BufRead *.properties_??_??_*	call s:StarSetf('jproperties')
910
911" Jess
912au BufNewFile,BufRead *.clp			setf jess
913
914" Jgraph
915au BufNewFile,BufRead *.jgr			setf jgraph
916
917" Kixtart
918au BufNewFile,BufRead *.kix			setf kix
919
920" Kimwitu[++]
921au BufNewFile,BufRead *.k			setf kwt
922
923" KDE script
924au BufNewFile,BufRead *.ks			setf kscript
925
926" Kconfig
927au BufNewFile,BufRead Kconfig,Kconfig.debug	setf kconfig
928
929" Lace (ISE)
930au BufNewFile,BufRead *.ace,*.ACE		setf lace
931
932" Latte
933au BufNewFile,BufRead *.latte,*.lte		setf latte
934
935" Limits
936au BufNewFile,BufRead /etc/limits		setf limits
937
938" LambdaProlog (*.mod too, see Modsim)
939au BufNewFile,BufRead *.sig			setf lprolog
940
941" LDAP LDIF
942au BufNewFile,BufRead *.ldif			setf ldif
943
944" Ld loader
945au BufNewFile,BufRead *.ld			setf ld
946
947" Lex
948au BufNewFile,BufRead *.lex,*.l			setf lex
949
950" Libao
951au BufNewFile,BufRead /etc/libao.conf,*/.libao	setf libao
952
953" Libsensors
954au BufNewFile,BufRead /etc/sensors.conf		setf sensors
955
956" LFTP
957au BufNewFile,BufRead lftp.conf,.lftprc,*lftp/rc	setf lftp
958
959" Lifelines (or Lex for C++!)
960au BufNewFile,BufRead *.ll			setf lifelines
961
962" Lilo: Linux loader
963au BufNewFile,BufRead lilo.conf*		call s:StarSetf('lilo')
964
965" Lisp (*.el = ELisp, *.cl = Common Lisp, *.jl = librep Lisp)
966if has("fname_case")
967  au BufNewFile,BufRead *.lsp,*.lisp,*.el,*.cl,*.jl,*.L,.emacs,.sawfishrc setf lisp
968else
969  au BufNewFile,BufRead *.lsp,*.lisp,*.el,*.cl,*.jl,.emacs,.sawfishrc setf lisp
970endif
971
972" SBCL implementation of Common Lisp
973au BufNewFile,BufRead sbclrc,.sbclrc		setf lisp
974
975" Lite
976au BufNewFile,BufRead *.lite,*.lt		setf lite
977
978" LiteStep RC files
979au BufNewFile,BufRead */LiteStep/*/*.rc		setf litestep
980
981" Login access
982au BufNewFile,BufRead /etc/login.access		setf loginaccess
983
984" Login defs
985au BufNewFile,BufRead /etc/login.defs		setf logindefs
986
987" Logtalk
988au BufNewFile,BufRead *.lgt			setf logtalk
989
990" LOTOS
991au BufNewFile,BufRead *.lot,*.lotos		setf lotos
992
993" Lout (also: *.lt)
994au BufNewFile,BufRead *.lou,*.lout		setf lout
995
996" Lua
997au BufNewFile,BufRead *.lua			setf lua
998
999" Linden Scripting Language (Second Life)
1000au BufNewFile,BufRead *.lsl			setf lsl
1001
1002" Lynx style file (or LotusScript!)
1003au BufNewFile,BufRead *.lss			setf lss
1004
1005" M4
1006au BufNewFile,BufRead *.m4
1007	\ if expand("<afile>") !~? 'html.m4$\|fvwm2rc' | setf m4 | endif
1008
1009" MaGic Point
1010au BufNewFile,BufRead *.mgp			setf mgp
1011
1012" Mail (for Elm, trn, mutt, muttng, rn, slrn)
1013au BufNewFile,BufRead snd.\d\+,.letter,.letter.\d\+,.followup,.article,.article.\d\+,pico.\d\+,mutt{ng,}-*-\w\+,mutt[[:alnum:]_-]\{6\},ae\d\+.txt,/tmp/SLRN[0-9A-Z.]\+,*.eml setf mail
1014
1015" Mail aliases
1016au BufNewFile,BufRead /etc/mail/aliases,/etc/aliases	setf mailaliases
1017
1018" Mailcap configuration file
1019au BufNewFile,BufRead .mailcap,mailcap		setf mailcap
1020
1021" Makefile
1022au BufNewFile,BufRead *[mM]akefile,*.mk,*.mak,*.dsp setf make
1023
1024" MakeIndex
1025au BufNewFile,BufRead *.ist,*.mst		setf ist
1026
1027" Manpage
1028au BufNewFile,BufRead *.man			setf man
1029
1030" Man config
1031au BufNewFile,BufRead /etc/man.conf,man.config	setf manconf
1032
1033" Maple V
1034au BufNewFile,BufRead *.mv,*.mpl,*.mws		setf maple
1035
1036" Map (UMN mapserver config file)
1037au BufNewFile,BufRead *.map			setf map
1038
1039" Mason
1040au BufNewFile,BufRead *.mason,*.mhtml		setf mason
1041
1042" Matlab or Objective C
1043au BufNewFile,BufRead *.m			call s:FTm()
1044
1045func! s:FTm()
1046  let n = 1
1047  while n < 10
1048    let line = getline(n)
1049    if line =~ '^\s*\(#\s*\(include\|import\)\>\|/\*\|//\)'
1050      setf objc
1051      return
1052    endif
1053    if line =~ '^\s*%'
1054      setf matlab
1055      return
1056    endif
1057    if line =~ '^\s*(\*'
1058      setf mma
1059      return
1060    endif
1061    let n = n + 1
1062  endwhile
1063  if exists("g:filetype_m")
1064    exe "setf " . g:filetype_m
1065  else
1066    setf matlab
1067  endif
1068endfunc
1069
1070" Mathematica notebook
1071au BufNewFile,BufRead *.nb			setf mma
1072
1073" Maya Extension Language
1074au BufNewFile,BufRead *.mel			setf mel
1075
1076" Mercurial config (looks like generic config file)
1077au BufNewFile,BufRead *.hgrc,*hgrc		setf cfg
1078
1079" Messages
1080au BufNewFile,BufRead /var/log/messages,/var/log/messages.*[0-9]  setf messages
1081
1082" Metafont
1083au BufNewFile,BufRead *.mf			setf mf
1084
1085" MetaPost
1086au BufNewFile,BufRead *.mp			setf mp
1087
1088" MGL
1089au BufNewFile,BufRead *.mgl			setf mgl
1090
1091" MMIX or VMS makefile
1092au BufNewFile,BufRead *.mms			call s:FTmms()
1093
1094" Symbian meta-makefile definition (MMP)
1095au BufNewFile,BufRead *.mmp			setf mmp
1096
1097func! s:FTmms()
1098  let n = 1
1099  while n < 10
1100    let line = getline(n)
1101    if line =~ '^\s*\(%\|//\)' || line =~ '^\*'
1102      setf mmix
1103      return
1104    endif
1105    if line =~ '^\s*#'
1106      setf make
1107      return
1108    endif
1109    let n = n + 1
1110  endwhile
1111  setf mmix
1112endfunc
1113
1114
1115" Modsim III (or LambdaProlog)
1116au BufNewFile,BufRead *.mod
1117	\ if getline(1) =~ '\<module\>' |
1118	\   setf lprolog |
1119	\ else |
1120	\   setf modsim3 |
1121	\ endif
1122
1123" Modula 2
1124au BufNewFile,BufRead *.m2,*.DEF,*.MOD,*.md,*.mi setf modula2
1125
1126" Modula 3 (.m3, .i3, .mg, .ig)
1127au BufNewFile,BufRead *.[mi][3g]		setf modula3
1128
1129" Monk
1130au BufNewFile,BufRead *.isc,*.monk,*.ssc,*.tsc	setf monk
1131
1132" MOO
1133au BufNewFile,BufRead *.moo			setf moo
1134
1135" Modconf
1136au BufNewFile,BufRead /etc/modules.conf,/etc/conf.modules	setf modconf
1137au BufNewFile,BufRead /etc/modutils/*
1138	\ if executable(expand("<afile>")) != 1
1139	\|  call s:StarSetf('modconf')
1140	\|endif
1141
1142" Mplayer config
1143au BufNewFile,BufRead mplayer.conf,*/.mplayer/config	setf mplayerconf
1144
1145" Moterola S record
1146au BufNewFile,BufRead *.s19,*.s28,*.s37		setf srec
1147
1148" Mrxvtrc
1149au BufNewFile,BufRead mrxvtrc,.mrxvtrc		setf mrxvtrc
1150
1151" Msql
1152au BufNewFile,BufRead *.msql			setf msql
1153
1154" Mysql
1155au BufNewFile,BufRead *.mysql			setf mysql
1156
1157" M$ Resource files
1158au BufNewFile,BufRead *.rc			setf rc
1159
1160" MuPAD source
1161au BufRead,BufNewFile *.mu			setf mupad
1162
1163" Mush
1164au BufNewFile,BufRead *.mush			setf mush
1165
1166" Mutt setup file (also for Muttng)
1167au BufNewFile,BufRead Mutt{ng,}rc		setf muttrc
1168
1169" Nano
1170au BufNewFile,BufRead /etc/nanorc,.nanorc	setf nanorc
1171
1172" Nastran input/DMAP
1173"au BufNewFile,BufRead *.dat			setf nastran
1174
1175" Natural
1176au BufNewFile,BufRead *.NS[ACGLMNPS]		setf natural
1177
1178" Netrc
1179au BufNewFile,BufRead .netrc			setf netrc
1180
1181" Novell netware batch files
1182au BufNewFile,BufRead *.ncf			setf ncf
1183
1184" Nroff/Troff (*.ms and *.t are checked below)
1185au BufNewFile,BufRead *.me
1186	\ if expand("<afile>") != "read.me" && expand("<afile>") != "click.me" |
1187	\   setf nroff |
1188	\ endif
1189au BufNewFile,BufRead *.tr,*.nr,*.roff,*.tmac,*.mom	setf nroff
1190au BufNewFile,BufRead *.[1-9]			call s:FTnroff()
1191
1192" This function checks if one of the first five lines start with a dot.  In
1193" that case it is probably an nroff file: 'filetype' is set and 1 is returned.
1194func! s:FTnroff()
1195  if getline(1)[0] . getline(2)[0] . getline(3)[0] . getline(4)[0] . getline(5)[0] =~ '\.'
1196    setf nroff
1197    return 1
1198  endif
1199  return 0
1200endfunc
1201
1202" Nroff or Objective C++
1203au BufNewFile,BufRead *.mm			call s:FTmm()
1204
1205func! s:FTmm()
1206  let n = 1
1207  while n < 10
1208    let line = getline(n)
1209    if line =~ '^\s*\(#\s*\(include\|import\)\>\|/\*\)'
1210      setf objcpp
1211      return
1212    endif
1213    let n = n + 1
1214  endwhile
1215  setf nroff
1216endfunc
1217
1218" Not Quite C
1219au BufNewFile,BufRead *.nqc			setf nqc
1220
1221" NSIS
1222au BufNewFile,BufRead *.nsi			setf nsis
1223
1224" OCAML
1225au BufNewFile,BufRead *.ml,*.mli,*.mll,*.mly	setf ocaml
1226
1227" Occam
1228au BufNewFile,BufRead *.occ			setf occam
1229
1230" Omnimark
1231au BufNewFile,BufRead *.xom,*.xin		setf omnimark
1232
1233" OpenROAD
1234au BufNewFile,BufRead *.or			setf openroad
1235
1236" OPL
1237au BufNewFile,BufRead *.[Oo][Pp][Ll]		setf opl
1238
1239" Oracle config file
1240au BufNewFile,BufRead *.ora			setf ora
1241
1242" Packet filter conf
1243au BufNewFile,BufRead pf.conf			setf pf
1244
1245" Pam conf
1246au BufNewFile,BufRead /etc/pam.conf		setf pamconf
1247
1248" PApp
1249au BufNewFile,BufRead *.papp,*.pxml,*.pxsl	setf papp
1250
1251" Password file
1252au BufNewFile,BufRead /etc/passwd,/etc/passwd-,/etc/passwd.edit,/etc/shadow,/etc/shadow-,/var/backups/passwd.bak,/var/backups/shadow.bak setf passwd
1253
1254" Pascal (also *.p)
1255au BufNewFile,BufRead *.pas			setf pascal
1256
1257" Delphi project file
1258au BufNewFile,BufRead *.dpr			setf pascal
1259
1260" PDF
1261au BufNewFile,BufRead *.pdf			setf pdf
1262
1263" Perl
1264if has("fname_case")
1265  au BufNewFile,BufRead *.pl,*.PL		call s:FTpl()
1266else
1267  au BufNewFile,BufRead *.pl			call s:FTpl()
1268endif
1269au BufNewFile,BufRead *.plx,*.al		setf perl
1270
1271func! s:FTpl()
1272  if exists("g:filetype_pl")
1273    exe "setf " . g:filetype_pl
1274  else
1275    " recognize Prolog by specific text in the first non-empty line
1276    " require a blank after the '%' because Perl uses "%list" and "%translate"
1277    let l = getline(nextnonblank(1))
1278    if l =~ '\<prolog\>' || l =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || l =~ ':-'
1279      setf prolog
1280    else
1281      setf perl
1282    endif
1283  endif
1284endfunc
1285
1286" Perl, XPM or XPM2
1287au BufNewFile,BufRead *.pm
1288	\ if getline(1) =~ "XPM2" |
1289	\   setf xpm2 |
1290	\ elseif getline(1) =~ "XPM" |
1291	\   setf xpm |
1292	\ else |
1293	\   setf perl |
1294	\ endif
1295
1296" Perl POD
1297au BufNewFile,BufRead *.pod			setf pod
1298
1299" Php, php3, php4, etc.
1300" Also Phtml (was used for PHP 2 in the past)
1301" Also .ctp for Cake template file
1302au BufNewFile,BufRead *.php,*.php\d,*.phtml,*.ctp	setf php
1303
1304" Pike
1305au BufNewFile,BufRead *.pike,*.lpc,*.ulpc,*.pmod setf pike
1306
1307" Pinfo config
1308au BufNewFile,BufRead */etc/pinforc,*/.pinforc	setf pinfo
1309
1310" Palm Resource compiler
1311au BufNewFile,BufRead *.rcp			setf pilrc
1312
1313" Pine config
1314au BufNewFile,BufRead .pinerc,pinerc,.pinercex,pinercex		setf pine
1315
1316" PL/M (also: *.inp)
1317au BufNewFile,BufRead *.plm,*.p36,*.pac		setf plm
1318
1319" PL/SQL
1320au BufNewFile,BufRead *.pls,*.plsql		setf plsql
1321
1322" PLP
1323au BufNewFile,BufRead *.plp			setf plp
1324
1325" PO and PO template (GNU gettext)
1326au BufNewFile,BufRead *.po,*.pot		setf po
1327
1328" Postfix main config
1329au BufNewFile,BufRead main.cf			setf pfmain
1330
1331" PostScript (+ font files, encapsulated PostScript, Adobe Illustrator)
1332au BufNewFile,BufRead *.ps,*.pfa,*.afm,*.eps,*.epsf,*.epsi,*.ai	  setf postscr
1333
1334" PostScript Printer Description
1335au BufNewFile,BufRead *.ppd			setf ppd
1336
1337" Povray
1338au BufNewFile,BufRead *.pov			setf pov
1339
1340" Povray configuration
1341au BufNewFile,BufRead .povrayrc			setf povini
1342
1343" Povray, PHP or assembly
1344au BufNewFile,BufRead *.inc			call s:FTinc()
1345
1346func! s:FTinc()
1347  if exists("g:filetype_inc")
1348    exe "setf " . g:filetype_inc
1349  else
1350    let lines = getline(1).getline(2).getline(3)
1351    if lines =~? "perlscript"
1352      setf aspperl
1353    elseif lines =~ "<%"
1354      setf aspvbs
1355    elseif lines =~ "<?"
1356      setf php
1357    else
1358      call s:FTasmsyntax()
1359      if exists("b:asmsyntax")
1360	exe "setf " . fnameescape(b:asmsyntax)
1361      else
1362	setf pov
1363      endif
1364    endif
1365  endif
1366endfunc
1367
1368" Printcap and Termcap
1369au BufNewFile,BufRead *printcap
1370	\ let b:ptcap_type = "print" | setf ptcap
1371au BufNewFile,BufRead *termcap
1372	\ let b:ptcap_type = "term" | setf ptcap
1373
1374" PCCTS / ANTRL
1375"au BufNewFile,BufRead *.g			setf antrl
1376au BufNewFile,BufRead *.g			setf pccts
1377
1378" PPWizard
1379au BufNewFile,BufRead *.it,*.ih			setf ppwiz
1380
1381" Oracle Pro*C/C++
1382au BufNewFile,BufRead *.pc			setf proc
1383
1384" Privoxy actions file
1385au BufNewFile,BufRead *.action			setf privoxy
1386
1387" Procmail
1388au BufNewFile,BufRead .procmail,.procmailrc	setf procmail
1389
1390" Progress or CWEB
1391au BufNewFile,BufRead *.w			call s:FTprogress_cweb()
1392
1393func! s:FTprogress_cweb()
1394  if exists("g:filetype_w")
1395    exe "setf " . g:filetype_w
1396    return
1397  endif
1398  if getline(1) =~ '&ANALYZE' || getline(3) =~ '&GLOBAL-DEFINE'
1399    setf progress
1400  else
1401    setf cweb
1402  endif
1403endfunc
1404
1405" Progress or assembly
1406au BufNewFile,BufRead *.i			call s:FTprogress_asm()
1407
1408func! s:FTprogress_asm()
1409  if exists("g:filetype_i")
1410    exe "setf " . g:filetype_i
1411    return
1412  endif
1413  " This function checks for an assembly comment the first ten lines.
1414  " If not found, assume Progress.
1415  let lnum = 1
1416  while lnum <= 10 && lnum < line('$')
1417    let line = getline(lnum)
1418    if line =~ '^\s*;' || line =~ '^\*'
1419      call s:FTasm()
1420      return
1421    elseif line !~ '^\s*$' || line =~ '^/\*'
1422      " Not an empty line: Doesn't look like valid assembly code.
1423      " Or it looks like a Progress /* comment
1424      break
1425    endif
1426    let lnum = lnum + 1
1427  endw
1428  setf progress
1429endfunc
1430
1431" Progress or Pascal
1432au BufNewFile,BufRead *.p			call s:FTprogress_pascal()
1433
1434func! s:FTprogress_pascal()
1435  if exists("g:filetype_p")
1436    exe "setf " . g:filetype_p
1437    return
1438  endif
1439  " This function checks for valid Pascal syntax in the first ten lines.
1440  " Look for either an opening comment or a program start.
1441  " If not found, assume Progress.
1442  let lnum = 1
1443  while lnum <= 10 && lnum < line('$')
1444    let line = getline(lnum)
1445    if line =~ '^\s*\(program\|unit\|procedure\|function\|const\|type\|var\)\>'
1446	\ || line =~ '^\s*{' || line =~ '^\s*(\*'
1447      setf pascal
1448      return
1449    elseif line !~ '^\s*$' || line =~ '^/\*'
1450      " Not an empty line: Doesn't look like valid Pascal code.
1451      " Or it looks like a Progress /* comment
1452      break
1453    endif
1454    let lnum = lnum + 1
1455  endw
1456  setf progress
1457endfunc
1458
1459
1460" Software Distributor Product Specification File (POSIX 1387.2-1995)
1461au BufNewFile,BufRead *.psf			setf psf
1462au BufNewFile,BufRead INDEX,INFO
1463	\ if getline(1) =~ '^\s*\(distribution\|installed_software\|root\|bundle\|product\)\s*$' |
1464	\   setf psf |
1465	\ endif
1466
1467" Prolog
1468au BufNewFile,BufRead *.pdb			setf prolog
1469
1470" Promela
1471au BufNewFile,BufRead *.pml			setf promela
1472
1473" Protocols
1474au BufNewFile,BufRead /etc/protocols		setf protocols
1475
1476" Pyrex
1477au BufNewFile,BufRead *.pyx,*.pxd		setf pyrex
1478
1479" Python
1480au BufNewFile,BufRead *.py,*.pyw		setf python
1481
1482" Quixote (Python-based web framework)
1483au BufNewFile,BufRead *.ptl			setf python
1484
1485" Radiance
1486au BufNewFile,BufRead *.rad,*.mat		setf radiance
1487
1488" Ratpoison config/command files
1489au BufNewFile,BufRead .ratpoisonrc,ratpoisonrc	setf ratpoison
1490
1491" RCS file
1492au BufNewFile,BufRead *\,v			setf rcs
1493
1494" Readline
1495au BufNewFile,BufRead .inputrc,inputrc		setf readline
1496
1497" Registry for MS-Windows
1498au BufNewFile,BufRead *.reg
1499	\ if getline(1) =~? '^REGEDIT[0-9]*\s*$\|^Windows Registry Editor Version \d*\.\d*\s*$' | setf registry | endif
1500
1501" Renderman Interface Bytestream
1502au BufNewFile,BufRead *.rib			setf rib
1503
1504" Rexx
1505au BufNewFile,BufRead *.rexx,*.rex,*.jrexx,*.rxj,*.orx	setf rexx
1506
1507" R (Splus)
1508if has("fname_case")
1509  au BufNewFile,BufRead *.s,*.S			setf r
1510else
1511  au BufNewFile,BufRead *.s			setf r
1512endif
1513
1514" R Help file
1515if has("fname_case")
1516  au BufNewFile,BufRead *.rd,*.Rd		setf rhelp
1517else
1518  au BufNewFile,BufRead *.rd			setf rhelp
1519endif
1520
1521" R noweb file
1522if has("fname_case")
1523  au BufNewFile,BufRead *.Rnw,*.rnw,*.Snw,*.snw		setf rnoweb
1524else
1525  au BufNewFile,BufRead *.rnw,*.snw			setf rnoweb
1526endif
1527
1528" Rexx, Rebol or R
1529au BufNewFile,BufRead *.r,*.R			call s:FTr()
1530
1531func! s:FTr()
1532  let max = line("$") > 50 ? 50 : line("$")
1533
1534  for n in range(1, max)
1535    " Rebol is easy to recognize, check for that first
1536    if getline(n) =~? '\<REBOL\>'
1537      setf rebol
1538      return
1539    endif
1540  endfor
1541
1542  for n in range(1, max)
1543    " R has # comments
1544    if getline(n) =~ '^\s*#'
1545      setf r
1546      return
1547    endif
1548    " Rexx has /* comments */
1549    if getline(n) =~ '^\s*/\*'
1550      setf rexx
1551      return
1552    endif
1553  endfor
1554
1555  " Nothing recognized, assume Rexx
1556  setf rexx
1557endfunc
1558
1559" Remind
1560au BufNewFile,BufRead .reminders*		call s:StarSetf('remind')
1561au BufNewFile,BufRead *.remind,*.rem		setf remind
1562
1563" Resolv.conf
1564au BufNewFile,BufRead resolv.conf		setf resolv
1565
1566" Relax NG Compact
1567au BufNewFile,BufRead *.rnc			setf rnc
1568
1569" RPL/2
1570au BufNewFile,BufRead *.rpl			setf rpl
1571
1572" Robots.txt
1573au BufNewFile,BufRead robots.txt		setf robots
1574
1575" Rpcgen
1576au BufNewFile,BufRead *.x			setf rpcgen
1577
1578" reStructuredText Documentation Format
1579au BufNewFile,BufRead *.rst			setf rst
1580
1581" RTF
1582au BufNewFile,BufRead *.rtf			setf rtf
1583
1584" Interactive Ruby shell
1585au BufNewFile,BufRead .irbrc,irbrc		setf ruby
1586
1587" Ruby
1588au BufNewFile,BufRead *.rb,*.rbw,*.gem,*.gemspec	setf ruby
1589
1590" Ruby on Rails
1591au BufNewFile,BufRead *.builder,*.rxml,*.rjs	setf ruby
1592
1593" Rantfile and Rakefile is like Ruby
1594au BufNewFile,BufRead [rR]antfile,*.rant,[rR]akefile,*.rake	setf ruby
1595
1596" S-lang (or shader language, or SmallLisp)
1597au BufNewFile,BufRead *.sl			setf slang
1598
1599" Samba config
1600au BufNewFile,BufRead smb.conf			setf samba
1601
1602" SAS script
1603au BufNewFile,BufRead *.sas			setf sas
1604
1605" Sass
1606au BufNewFile,BufRead *.sass			setf sass
1607
1608" Sather
1609au BufNewFile,BufRead *.sa			setf sather
1610
1611" Scilab
1612au BufNewFile,BufRead *.sci,*.sce		setf scilab
1613
1614" SD: Streaming Descriptors
1615au BufNewFile,BufRead *.sd			setf sd
1616
1617" SDL
1618au BufNewFile,BufRead *.sdl,*.pr		setf sdl
1619
1620" sed
1621au BufNewFile,BufRead *.sed			setf sed
1622
1623" Sieve (RFC 3028)
1624au BufNewFile,BufRead *.siv			setf sieve
1625
1626" Sendmail
1627au BufNewFile,BufRead sendmail.cf		setf sm
1628
1629" Sendmail .mc files are actually m4.  Could also be MS Message text file.
1630au BufNewFile,BufRead *.mc			call s:McSetf()
1631
1632func! s:McSetf()
1633  " Rely on the file to start with a comment.
1634  " MS message text files use ';', Sendmail files use '#' or 'dnl'
1635  for lnum in range(1, min([line("$"), 20]))
1636    let line = getline(lnum)
1637    if line =~ '^\s*\(#\|dnl\)'
1638      setf m4  " Sendmail .mc file
1639      return
1640    elseif line =~ '^\s*;'
1641      setf msmessages  " MS Message text file
1642      return
1643    endif
1644  endfor
1645  setf m4  " Default: Sendmail .mc file
1646endfunc
1647
1648" Services
1649au BufNewFile,BufRead /etc/services		setf services
1650
1651" Service Location config
1652au BufNewFile,BufRead /etc/slp.conf		setf slpconf
1653
1654" Service Location registration
1655au BufNewFile,BufRead /etc/slp.reg		setf slpreg
1656
1657" Service Location SPI
1658au BufNewFile,BufRead /etc/slp.spi		setf slpspi
1659
1660" Setserial config
1661au BufNewFile,BufRead /etc/serial.conf		setf setserial
1662
1663" SGML
1664au BufNewFile,BufRead *.sgm,*.sgml
1665	\ if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'linuxdoc' |
1666	\   setf sgmllnx |
1667	\ elseif getline(1) =~ '<!DOCTYPE.*DocBook' || getline(2) =~ '<!DOCTYPE.*DocBook' |
1668	\   let b:docbk_type="sgml" |
1669	\   setf docbk |
1670	\ else |
1671	\   setf sgml |
1672	\ endif
1673
1674" SGMLDECL
1675au BufNewFile,BufRead *.decl,*.dcl,*.dec
1676	\ if getline(1).getline(2).getline(3) =~? '^<!SGML' |
1677	\    setf sgmldecl |
1678	\ endif
1679
1680" SGML catalog file
1681au BufNewFile,BufRead catalog			setf catalog
1682au BufNewFile,BufRead sgml.catalog*		call s:StarSetf('catalog')
1683
1684" Shell scripts (sh, ksh, bash, bash2, csh); Allow .profile_foo etc.
1685" Gentoo ebuilds are actually bash scripts
1686au BufNewFile,BufRead .bashrc*,bashrc,bash.bashrc,.bash_profile*,.bash_logout*,*.bash,*.ebuild call SetFileTypeSH("bash")
1687au BufNewFile,BufRead .kshrc*,*.ksh call SetFileTypeSH("ksh")
1688au BufNewFile,BufRead /etc/profile,.profile*,*.sh,*.env call SetFileTypeSH(getline(1))
1689
1690" Also called from scripts.vim.
1691func! SetFileTypeSH(name)
1692  if expand("<amatch>") =~ g:ft_ignore_pat
1693    return
1694  endif
1695  if a:name =~ '\<csh\>'
1696    " Some .sh scripts contain #!/bin/csh.
1697    call SetFileTypeShell("csh")
1698    return
1699  elseif a:name =~ '\<tcsh\>'
1700    " Some .sh scripts contain #!/bin/tcsh.
1701    call SetFileTypeShell("tcsh")
1702    return
1703  elseif a:name =~ '\<ksh\>'
1704    let b:is_kornshell = 1
1705    if exists("b:is_bash")
1706      unlet b:is_bash
1707    endif
1708    if exists("b:is_sh")
1709      unlet b:is_sh
1710    endif
1711  elseif exists("g:bash_is_sh") || a:name =~ '\<bash\>' || a:name =~ '\<bash2\>'
1712    let b:is_bash = 1
1713    if exists("b:is_kornshell")
1714      unlet b:is_kornshell
1715    endif
1716    if exists("b:is_sh")
1717      unlet b:is_sh
1718    endif
1719  elseif a:name =~ '\<sh\>'
1720    let b:is_sh = 1
1721    if exists("b:is_kornshell")
1722      unlet b:is_kornshell
1723    endif
1724    if exists("b:is_bash")
1725      unlet b:is_bash
1726    endif
1727  endif
1728  call SetFileTypeShell("sh")
1729endfunc
1730
1731" For shell-like file types, check for an "exec" command hidden in a comment,
1732" as used for Tcl.
1733" Also called from scripts.vim, thus can't be local to this script.
1734func! SetFileTypeShell(name)
1735  if expand("<amatch>") =~ g:ft_ignore_pat
1736    return
1737  endif
1738  let l = 2
1739  while l < 20 && l < line("$") && getline(l) =~ '^\s*\(#\|$\)'
1740    " Skip empty and comment lines.
1741    let l = l + 1
1742  endwhile
1743  if l < line("$") && getline(l) =~ '\s*exec\s' && getline(l - 1) =~ '^\s*#.*\\$'
1744    " Found an "exec" line after a comment with continuation
1745    let n = substitute(getline(l),'\s*exec\s\+\([^ ]*/\)\=', '', '')
1746    if n =~ '\<tclsh\|\<wish'
1747      setf tcl
1748      return
1749    endif
1750  endif
1751  exe "setf " . a:name
1752endfunc
1753
1754" tcsh scripts
1755au BufNewFile,BufRead .tcshrc*,*.tcsh,tcsh.tcshrc,tcsh.login	call SetFileTypeShell("tcsh")
1756
1757" csh scripts, but might also be tcsh scripts (on some systems csh is tcsh)
1758au BufNewFile,BufRead .login*,.cshrc*,csh.cshrc,csh.login,csh.logout,*.csh,.alias  call s:CSH()
1759
1760func! s:CSH()
1761  if exists("g:filetype_csh")
1762    call SetFileTypeShell(g:filetype_csh)
1763  elseif &shell =~ "tcsh"
1764    call SetFileTypeShell("tcsh")
1765  else
1766    call SetFileTypeShell("csh")
1767  endif
1768endfunc
1769
1770" Z-Shell script
1771au BufNewFile,BufRead .zprofile,/etc/zprofile,.zfbfmarks  setf zsh
1772au BufNewFile,BufRead .zsh*,.zlog*,.zcompdump*  call s:StarSetf('zsh')
1773au BufNewFile,BufRead *.zsh 			setf zsh
1774
1775" Scheme
1776au BufNewFile,BufRead *.scm,*.ss		setf scheme
1777
1778" Screen RC
1779au BufNewFile,BufRead .screenrc,screenrc	setf screen
1780
1781" Simula
1782au BufNewFile,BufRead *.sim			setf simula
1783
1784" SINDA
1785au BufNewFile,BufRead *.sin,*.s85		setf sinda
1786
1787" SiSU
1788au BufNewFile,BufRead *.sst,*.ssm,*.ssi,*.-sst,*._sst setf sisu
1789au BufNewFile,BufRead *.sst.meta,*.-sst.meta,*._sst.meta setf sisu
1790
1791" SKILL
1792au BufNewFile,BufRead *.il,*.ils,*.cdf		setf skill
1793
1794" SLRN
1795au BufNewFile,BufRead .slrnrc			setf slrnrc
1796au BufNewFile,BufRead *.score			setf slrnsc
1797
1798" Smalltalk (and TeX)
1799au BufNewFile,BufRead *.st			setf st
1800au BufNewFile,BufRead *.cls
1801	\ if getline(1) =~ '^%' |
1802	\  setf tex |
1803	\ else |
1804	\  setf st |
1805	\ endif
1806
1807" Smarty templates
1808au BufNewFile,BufRead *.tpl			setf smarty
1809
1810" SMIL or XML
1811au BufNewFile,BufRead *.smil
1812	\ if getline(1) =~ '<?\s*xml.*?>' |
1813	\   setf xml |
1814	\ else |
1815	\   setf smil |
1816	\ endif
1817
1818" SMIL or SNMP MIB file
1819au BufNewFile,BufRead *.smi
1820	\ if getline(1) =~ '\<smil\>' |
1821	\   setf smil |
1822	\ else |
1823	\   setf mib |
1824	\ endif
1825
1826" SMITH
1827au BufNewFile,BufRead *.smt,*.smith		setf smith
1828
1829" Snobol4 and spitbol
1830au BufNewFile,BufRead *.sno,*.spt		setf snobol4
1831
1832" SNMP MIB files
1833au BufNewFile,BufRead *.mib,*.my		setf mib
1834
1835" Snort Configuration
1836au BufNewFile,BufRead *.hog,snort.conf,vision.conf	setf hog
1837au BufNewFile,BufRead *.rules			call s:FTRules()
1838
1839let s:ft_rules_udev_rules_pattern = '^\s*\cudev_rules\s*=\s*"\([^"]\{-1,}\)/*".*'
1840func! s:FTRules()
1841  let path = expand('<amatch>:p')
1842  if path =~ '^/etc/udev/\%(rules\.d/\)\=.*\.rules$'
1843    setf udevrules
1844    return
1845  endif
1846  if path =~ '^/etc/ufw/'
1847    setf conf  " Better than hog
1848    return
1849  endif
1850  try
1851    let config_lines = readfile('/etc/udev/udev.conf')
1852  catch /^Vim\%((\a\+)\)\=:E484/
1853    setf hog
1854    return
1855  endtry
1856  let dir = expand('<amatch>:p:h')
1857  for line in config_lines
1858    if line =~ s:ft_rules_udev_rules_pattern
1859      let udev_rules = substitute(line, s:ft_rules_udev_rules_pattern, '\1', "")
1860      if dir == udev_rules
1861        setf udevrules
1862      endif
1863      break
1864    endif
1865  endfor
1866  setf hog
1867endfunc
1868
1869
1870" Spec (Linux RPM)
1871au BufNewFile,BufRead *.spec			setf spec
1872
1873" Speedup (AspenTech plant simulator)
1874au BufNewFile,BufRead *.speedup,*.spdata,*.spd	setf spup
1875
1876" Slice
1877au BufNewFile,BufRead *.ice			setf slice
1878
1879" Spice
1880au BufNewFile,BufRead *.sp,*.spice		setf spice
1881
1882" Spyce
1883au BufNewFile,BufRead *.spy,*.spi		setf spyce
1884
1885" Squid
1886au BufNewFile,BufRead squid.conf		setf squid
1887
1888" SQL for Oracle Designer
1889au BufNewFile,BufRead *.tyb,*.typ,*.tyc,*.pkb,*.pks	setf sql
1890
1891" SQL
1892au BufNewFile,BufRead *.sql			call s:SQL()
1893
1894func! s:SQL()
1895  if exists("g:filetype_sql")
1896    exe "setf " . g:filetype_sql
1897  else
1898    setf sql
1899  endif
1900endfunc
1901
1902" SQLJ
1903au BufNewFile,BufRead *.sqlj			setf sqlj
1904
1905" SQR
1906au BufNewFile,BufRead *.sqr,*.sqi		setf sqr
1907
1908" OpenSSH configuration
1909au BufNewFile,BufRead ssh_config,*/.ssh/config	setf sshconfig
1910
1911" OpenSSH server configuration
1912au BufNewFile,BufRead sshd_config		setf sshdconfig
1913
1914" Stata
1915au BufNewFile,BufRead *.ado,*.class,*.do,*.imata,*.mata   setf stata
1916
1917" SMCL
1918au BufNewFile,BufRead *.hlp,*.ihlp,*.smcl	setf smcl
1919
1920" Stored Procedures
1921au BufNewFile,BufRead *.stp			setf stp
1922
1923" Standard ML
1924au BufNewFile,BufRead *.sml			setf sml
1925
1926" Sratus VOS command macro
1927au BufNewFile,BufRead *.cm			setf voscm
1928
1929" Sysctl
1930au BufNewFile,BufRead /etc/sysctl.conf		setf sysctl
1931
1932" Synopsys Design Constraints
1933au BufNewFile,BufRead *.sdc			setf sdc
1934
1935" Sudoers
1936au BufNewFile,BufRead /etc/sudoers,sudoers.tmp	setf sudoers
1937
1938" If the file has an extension of 't' and is in a directory 't' then it is
1939" almost certainly a Perl test file.
1940" If the first line starts with '#' and contains 'perl' it's probably a Perl
1941" file.
1942" (Slow test) If a file contains a 'use' statement then it is almost certainly
1943" a Perl file.
1944func! s:FTperl()
1945  if expand("%:e") == 't' && expand("%:p:h:t") == 't'
1946    setf perl
1947    return 1
1948  endif
1949  if getline(1)[0] == '#' && getline(1) =~ 'perl'
1950    setf perl
1951    return 1
1952  endif
1953  if search('^use\s\s*\k', 'nc', 30)
1954    setf perl
1955    return 1
1956  endif
1957  return 0
1958endfunc
1959
1960" Tads (or Nroff or Perl test file)
1961au BufNewFile,BufRead *.t
1962	\ if !s:FTnroff() && !s:FTperl() | setf tads | endif
1963
1964" Tags
1965au BufNewFile,BufRead tags			setf tags
1966
1967" TAK
1968au BufNewFile,BufRead *.tak			setf tak
1969
1970" Task
1971au BufRead,BufNewFile {pending,completed,undo}.data  setf taskdata
1972au BufRead,BufNewFile *.task                    setf taskedit
1973
1974" Tcl (JACL too)
1975au BufNewFile,BufRead *.tcl,*.tk,*.itcl,*.itk,*.jacl	setf tcl
1976
1977" TealInfo
1978au BufNewFile,BufRead *.tli			setf tli
1979
1980" Telix Salt
1981au BufNewFile,BufRead *.slt			setf tsalt
1982
1983" Terminfo
1984au BufNewFile,BufRead *.ti			setf terminfo
1985
1986" TeX
1987au BufNewFile,BufRead *.latex,*.sty,*.dtx,*.ltx,*.bbl	setf tex
1988au BufNewFile,BufRead *.tex			call s:FTtex()
1989
1990" Choose context, plaintex, or tex (LaTeX) based on these rules:
1991" 1. Check the first line of the file for "%&<format>".
1992" 2. Check the first 1000 non-comment lines for LaTeX or ConTeXt keywords.
1993" 3. Default to "latex" or to g:tex_flavor, can be set in user's vimrc.
1994func! s:FTtex()
1995  let firstline = getline(1)
1996  if firstline =~ '^%&\s*\a\+'
1997    let format = tolower(matchstr(firstline, '\a\+'))
1998    let format = substitute(format, 'pdf', '', '')
1999    if format == 'tex'
2000      let format = 'plain'
2001    endif
2002  else
2003    " Default value, may be changed later:
2004    let format = exists("g:tex_flavor") ? g:tex_flavor : 'plain'
2005    " Save position, go to the top of the file, find first non-comment line.
2006    let save_cursor = getpos('.')
2007    call cursor(1,1)
2008    let firstNC = search('^\s*[^[:space:]%]', 'c', 1000)
2009    if firstNC " Check the next thousand lines for a LaTeX or ConTeXt keyword.
2010      let lpat = 'documentclass\>\|usepackage\>\|begin{\|newcommand\>\|renewcommand\>'
2011      let cpat = 'start\a\+\|setup\a\+\|usemodule\|enablemode\|enableregime\|setvariables\|useencoding\|usesymbols\|stelle\a\+\|verwende\a\+\|stel\a\+\|gebruik\a\+\|usa\a\+\|imposta\a\+\|regle\a\+\|utilisemodule\>'
2012      let kwline = search('^\s*\\\%(' . lpat . '\)\|^\s*\\\(' . cpat . '\)',
2013			      \ 'cnp', firstNC + 1000)
2014      if kwline == 1	" lpat matched
2015	let format = 'latex'
2016      elseif kwline == 2	" cpat matched
2017	let format = 'context'
2018      endif		" If neither matched, keep default set above.
2019      " let lline = search('^\s*\\\%(' . lpat . '\)', 'cn', firstNC + 1000)
2020      " let cline = search('^\s*\\\%(' . cpat . '\)', 'cn', firstNC + 1000)
2021      " if cline > 0
2022      "   let format = 'context'
2023      " endif
2024      " if lline > 0 && (cline == 0 || cline > lline)
2025      "   let format = 'tex'
2026      " endif
2027    endif " firstNC
2028    call setpos('.', save_cursor)
2029  endif " firstline =~ '^%&\s*\a\+'
2030
2031  " Translation from formats to file types.  TODO:  add AMSTeX, RevTex, others?
2032  if format == 'plain'
2033    setf plaintex
2034  elseif format == 'context'
2035    setf context
2036  else " probably LaTeX
2037    setf tex
2038  endif
2039  return
2040endfunc
2041
2042" ConTeXt
2043au BufNewFile,BufRead tex/context/*/*.tex,*.mkii,*.mkiv   setf context
2044
2045" Texinfo
2046au BufNewFile,BufRead *.texinfo,*.texi,*.txi	setf texinfo
2047
2048" TeX configuration
2049au BufNewFile,BufRead texmf.cnf			setf texmf
2050
2051" Tidy config
2052au BufNewFile,BufRead .tidyrc,tidyrc		setf tidy
2053
2054" TF mud client
2055au BufNewFile,BufRead *.tf,.tfrc,tfrc		setf tf
2056
2057" TPP - Text Presentation Program
2058au BufNewFile,BufReadPost *.tpp			setf tpp
2059
2060" Trustees
2061au BufNewFile,BufRead trustees.conf		setf trustees
2062
2063" TSS - Geometry
2064au BufNewFile,BufReadPost *.tssgm		setf tssgm
2065
2066" TSS - Optics
2067au BufNewFile,BufReadPost *.tssop		setf tssop
2068
2069" TSS - Command Line (temporary)
2070au BufNewFile,BufReadPost *.tsscl		setf tsscl
2071
2072" Motif UIT/UIL files
2073au BufNewFile,BufRead *.uit,*.uil		setf uil
2074
2075" Udev conf
2076au BufNewFile,BufRead /etc/udev/udev.conf	setf udevconf
2077
2078" Udev permissions
2079au BufNewFile,BufRead /etc/udev/permissions.d/*.permissions setf udevperm
2080"
2081" Udev symlinks config
2082au BufNewFile,BufRead /etc/udev/cdsymlinks.conf	setf sh
2083
2084" UnrealScript
2085au BufNewFile,BufRead *.uc			setf uc
2086
2087" Updatedb
2088au BufNewFile,BufRead /etc/updatedb.conf	setf updatedb
2089
2090" Vera
2091au BufNewFile,BufRead *.vr,*.vri,*.vrh		setf vera
2092
2093" Verilog HDL
2094au BufNewFile,BufRead *.v			setf verilog
2095
2096" Verilog-AMS HDL
2097au BufNewFile,BufRead *.va,*.vams		setf verilogams
2098
2099" VHDL
2100au BufNewFile,BufRead *.hdl,*.vhd,*.vhdl,*.vbe,*.vst  setf vhdl
2101au BufNewFile,BufRead *.vhdl_[0-9]*		call s:StarSetf('vhdl')
2102
2103" Vim script
2104au BufNewFile,BufRead *.vim,*.vba,.exrc,_exrc	setf vim
2105
2106" Viminfo file
2107au BufNewFile,BufRead .viminfo,_viminfo		setf viminfo
2108
2109" Virata Config Script File or Drupal module
2110au BufRead,BufNewFile *.hw,*.module,*.pkg
2111	\ if getline(1) =~ '<?php' |
2112	\   setf php |
2113	\ else |
2114	\   setf virata |
2115	\ endif
2116
2117" Visual Basic (also uses *.bas) or FORM
2118au BufNewFile,BufRead *.frm			call s:FTVB("form")
2119
2120" SaxBasic is close to Visual Basic
2121au BufNewFile,BufRead *.sba			setf vb
2122
2123" Vgrindefs file
2124au BufNewFile,BufRead vgrindefs			setf vgrindefs
2125
2126" VRML V1.0c
2127au BufNewFile,BufRead *.wrl			setf vrml
2128
2129" Webmacro
2130au BufNewFile,BufRead *.wm			setf webmacro
2131
2132" Wget config
2133au BufNewFile,BufRead .wgetrc,wgetrc		setf wget
2134
2135" Website MetaLanguage
2136au BufNewFile,BufRead *.wml			setf wml
2137
2138" Winbatch
2139au BufNewFile,BufRead *.wbt			setf winbatch
2140
2141" WSML
2142au BufNewFile,BufRead *.wsml			setf wsml
2143
2144" WvDial
2145au BufNewFile,BufRead wvdial.conf,.wvdialrc	setf wvdial
2146
2147" CVS RC file
2148au BufNewFile,BufRead .cvsrc			setf cvsrc
2149
2150" CVS commit file
2151au BufNewFile,BufRead cvs\d\+			setf cvs
2152
2153" WEB (*.web is also used for Winbatch: Guess, based on expecting "%" comment
2154" lines in a WEB file).
2155au BufNewFile,BufRead *.web
2156	\ if getline(1)[0].getline(2)[0].getline(3)[0].getline(4)[0].getline(5)[0] =~ "%" |
2157	\   setf web |
2158	\ else |
2159	\   setf winbatch |
2160	\ endif
2161
2162" Windows Scripting Host and Windows Script Component
2163au BufNewFile,BufRead *.ws[fc]			setf wsh
2164
2165" XHTML
2166au BufNewFile,BufRead *.xhtml,*.xht		setf xhtml
2167
2168" X Pixmap (dynamically sets colors, use BufEnter to make it work better)
2169au BufEnter *.xpm
2170	\ if getline(1) =~ "XPM2" |
2171	\   setf xpm2 |
2172	\ else |
2173	\   setf xpm |
2174	\ endif
2175au BufEnter *.xpm2				setf xpm2
2176
2177" XFree86 config
2178au BufNewFile,BufRead XF86Config
2179	\ if getline(1) =~ '\<XConfigurator\>' |
2180	\   let b:xf86c_xfree86_version = 3 |
2181	\ endif |
2182	\ setf xf86conf
2183
2184" Xorg config
2185au BufNewFile,BufRead xorg.conf,xorg.conf-4	let b:xf86c_xfree86_version = 4 | setf xf86conf
2186
2187" Xinetd conf
2188au BufNewFile,BufRead /etc/xinetd.conf		setf xinetd
2189
2190" XS Perl extension interface language
2191au BufNewFile,BufRead *.xs			setf xs
2192
2193" X resources file
2194au BufNewFile,BufRead .Xdefaults,.Xpdefaults,.Xresources,xdm-config,*.ad setf xdefaults
2195
2196" Xmath
2197au BufNewFile,BufRead *.msc,*.msf		setf xmath
2198au BufNewFile,BufRead *.ms
2199	\ if !s:FTnroff() | setf xmath | endif
2200
2201" XML  specific variants: docbk and xbl
2202au BufNewFile,BufRead *.xml			call s:FTxml()
2203
2204func! s:FTxml()
2205  let n = 1
2206  while n < 100 && n < line("$")
2207    let line = getline(n)
2208    if line =~ '<!DOCTYPE.*DocBook'
2209      let b:docbk_type = "xml"
2210      setf docbk
2211      return
2212    endif
2213    if line =~ 'xmlns:xbl="http://www.mozilla.org/xbl"'
2214      setf xbl
2215      return
2216    endif
2217    let n += 1
2218  endwhile
2219  setf xml
2220endfunc
2221
2222" XMI (holding UML models) is also XML
2223au BufNewFile,BufRead *.xmi			setf xml
2224
2225" CSPROJ files are Visual Studio.NET's XML-based project config files
2226au BufNewFile,BufRead *.csproj,*.csproj.user	setf xml
2227
2228" Qt Linguist translation source and Qt User Interface Files are XML
2229au BufNewFile,BufRead *.ts,*.ui			setf xml
2230
2231" TPM's are RDF-based descriptions of TeX packages (Nikolai Weibull)
2232au BufNewFile,BufRead *.tpm			setf xml
2233
2234" Xdg menus
2235au BufNewFile,BufRead /etc/xdg/menus/*.menu	setf xml
2236
2237" ATI graphics driver configuration
2238au BufNewFile,BufRead fglrxrc			setf xml
2239
2240" XLIFF (XML Localisation Interchange File Format) is also XML
2241au BufNewFile,BufRead *.xlf			setf xml
2242au BufNewFile,BufRead *.xliff			setf xml
2243
2244" X11 xmodmap (also see below)
2245au BufNewFile,BufRead *Xmodmap			setf xmodmap
2246
2247" Xquery
2248au BufNewFile,BufRead *.xq,*.xql,*.xqm,*.xquery,*.xqy	setf xquery
2249
2250" XSD
2251au BufNewFile,BufRead *.xsd			setf xsd
2252
2253" Xslt
2254au BufNewFile,BufRead *.xsl,*.xslt		setf xslt
2255
2256" Yacc
2257au BufNewFile,BufRead *.yy			setf yacc
2258
2259" Yacc or racc
2260au BufNewFile,BufRead *.y			call s:FTy()
2261
2262func! s:FTy()
2263  let n = 1
2264  while n < 100 && n < line("$")
2265    let line = getline(n)
2266    if line =~ '^\s*%'
2267      setf yacc
2268      return
2269    endif
2270    if getline(n) =~ '^\s*\(#\|class\>\)' && getline(n) !~ '^\s*#\s*include'
2271      setf racc
2272      return
2273    endif
2274    let n = n + 1
2275  endwhile
2276  setf yacc
2277endfunc
2278
2279
2280" Yaml
2281au BufNewFile,BufRead *.yaml,*.yml		setf yaml
2282
2283" Zope
2284"   dtml (zope dynamic template markup language), pt (zope page template),
2285"   cpt (zope form controller page template)
2286au BufNewFile,BufRead *.dtml,*.pt,*.cpt		call s:FThtml()
2287"   zsql (zope sql method)
2288au BufNewFile,BufRead *.zsql			call s:SQL()
2289
2290" Z80 assembler asz80
2291au BufNewFile,BufRead *.z8a			setf z8a
2292
2293augroup END
2294
2295
2296" Source the user-specified filetype file, for backwards compatibility with
2297" Vim 5.x.
2298if exists("myfiletypefile") && filereadable(expand(myfiletypefile))
2299  execute "source " . myfiletypefile
2300endif
2301
2302
2303" Check for "*" after loading myfiletypefile, so that scripts.vim is only used
2304" when there are no matching file name extensions.
2305" Don't do this for compressed files.
2306augroup filetypedetect
2307au BufNewFile,BufRead *
2308	\ if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat
2309	\ | runtime! scripts.vim | endif
2310au StdinReadPost * if !did_filetype() | runtime! scripts.vim | endif
2311
2312
2313" Extra checks for when no filetype has been detected now.  Mostly used for
2314" patterns that end in "*".  E.g., "zsh*" matches "zsh.vim", but that's a Vim
2315" script file.
2316" Most of these should call s:StarSetf() to avoid names ending in .gz and the
2317" like are used.
2318
2319" More Apache files.
2320au BufNewFile,BufRead /etc/apache2/conf.*/*,/etc/apache2/sites-*/*,/etc/apache2/mods-*/*		call s:StarSetf('apache')
2321
2322" Asterisk config file
2323au BufNewFile,BufRead *asterisk/*.conf*		call s:StarSetf('asterisk')
2324au BufNewFile,BufRead *asterisk*/*voicemail.conf* call s:StarSetf('asteriskvm')
2325
2326" Bazaar version control
2327au BufNewFile,BufRead bzr_log.*			setf bzr
2328
2329" BIND zone
2330au BufNewFile,BufRead */named/db.*,*/bind/db.*	call s:StarSetf('bindzone')
2331
2332" Changelog
2333au BufNewFile,BufRead [cC]hange[lL]og*
2334	\ if getline(1) =~ '; urgency='
2335	\|  call s:StarSetf('debchangelog')
2336	\|else
2337	\|  call s:StarSetf('changelog')
2338	\|endif
2339
2340" Crontab
2341au BufNewFile,BufRead crontab,crontab.*,/etc/cron.d/*		call s:StarSetf('crontab')
2342
2343" Debian Sources.list
2344au BufNewFile,BufRead /etc/apt/sources.list.d/*	call s:StarSetf('debsources')
2345
2346" Dracula
2347au BufNewFile,BufRead drac.*			call s:StarSetf('dracula')
2348
2349" Fvwm
2350au BufNewFile,BufRead */.fvwm/*			call s:StarSetf('fvwm')
2351au BufNewFile,BufRead *fvwmrc*,*fvwm95*.hook
2352	\ let b:fvwm_version = 1 | call s:StarSetf('fvwm')
2353au BufNewFile,BufRead *fvwm2rc*
2354	\ if expand("<afile>:e") == "m4"
2355	\|  call s:StarSetf('fvwm2m4')
2356	\|else
2357	\|  let b:fvwm_version = 2 | call s:StarSetf('fvwm')
2358	\|endif
2359
2360" Gedcom
2361au BufNewFile,BufRead /tmp/lltmp*		call s:StarSetf('gedcom')
2362
2363" GTK RC
2364au BufNewFile,BufRead .gtkrc*,gtkrc*		call s:StarSetf('gtkrc')
2365
2366" Jam
2367au BufNewFile,BufRead Prl*.*,JAM*.*		call s:StarSetf('jam')
2368
2369" Jargon
2370au! BufNewFile,BufRead *jarg*
2371	\ if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'THIS IS THE JARGON FILE'
2372	\|  call s:StarSetf('jargon')
2373	\|endif
2374
2375" Kconfig
2376au BufNewFile,BufRead Kconfig.*			call s:StarSetf('kconfig')
2377
2378" Makefile
2379au BufNewFile,BufRead [mM]akefile*		call s:StarSetf('make')
2380
2381" Ruby Makefile
2382au BufNewFile,BufRead [rR]akefile*		call s:StarSetf('ruby')
2383
2384" Mail (also matches muttrc.vim, so this is below the other checks)
2385au BufNewFile,BufRead mutt[[:alnum:]._-]\{6\}	setf mail
2386
2387" Modconf
2388au BufNewFile,BufRead /etc/modprobe.*		call s:StarSetf('modconf')
2389
2390" Mutt setup file
2391au BufNewFile,BufRead .mutt{ng,}rc*,*/.mutt{ng,}/mutt{ng,}rc*	call s:StarSetf('muttrc')
2392au BufNewFile,BufRead mutt{ng,}rc*,Mutt{ng,}rc*		call s:StarSetf('muttrc')
2393
2394" Nroff macros
2395au BufNewFile,BufRead tmac.*			call s:StarSetf('nroff')
2396
2397" Pam conf
2398au BufNewFile,BufRead /etc/pam.d/*		call s:StarSetf('pamconf')
2399
2400" Printcap and Termcap
2401au BufNewFile,BufRead *printcap*
2402	\ if !did_filetype()
2403	\|  let b:ptcap_type = "print" | call s:StarSetf('ptcap')
2404	\|endif
2405au BufNewFile,BufRead *termcap*
2406	\ if !did_filetype()
2407	\|  let b:ptcap_type = "term" | call s:StarSetf('ptcap')
2408	\|endif
2409
2410" Vim script
2411au BufNewFile,BufRead *vimrc*			call s:StarSetf('vim')
2412
2413" Subversion commit file
2414au BufNewFile,BufRead svn-commit*.tmp		setf svn
2415
2416" X resources file
2417au BufNewFile,BufRead Xresources*,*/app-defaults/*,*/Xresources/* call s:StarSetf('xdefaults')
2418
2419" XFree86 config
2420au BufNewFile,BufRead XF86Config-4*
2421	\ let b:xf86c_xfree86_version = 4 | call s:StarSetf('xf86conf')
2422au BufNewFile,BufRead XF86Config*
2423	\ if getline(1) =~ '\<XConfigurator\>'
2424	\|  let b:xf86c_xfree86_version = 3
2425	\|endif
2426	\|call s:StarSetf('xf86conf')
2427
2428" X11 xmodmap
2429au BufNewFile,BufRead *xmodmap*			call s:StarSetf('xmodmap')
2430
2431" Xinetd conf
2432au BufNewFile,BufRead /etc/xinetd.d/*		call s:StarSetf('xinetd')
2433
2434" Z-Shell script
2435au BufNewFile,BufRead zsh*,zlog*		call s:StarSetf('zsh')
2436
2437
2438
2439" Use the filetype detect plugins.  They may overrule any of the previously
2440" detected filetypes.
2441runtime! ftdetect/*.vim
2442
2443
2444" Generic configuration file (check this last, it's just guessing!)
2445au BufNewFile,BufRead,StdinReadPost *
2446	\ if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat
2447	\    && (getline(1) =~ '^#' || getline(2) =~ '^#' || getline(3) =~ '^#'
2448	\	|| getline(4) =~ '^#' || getline(5) =~ '^#') |
2449	\   setf conf |
2450	\ endif
2451
2452augroup END
2453
2454
2455" If the GUI is already running, may still need to install the Syntax menu.
2456" Don't do it when the 'M' flag is included in 'guioptions'.
2457if has("menu") && has("gui_running")
2458      \ && !exists("did_install_syntax_menu") && &guioptions !~# "M"
2459  source <sfile>:p:h/menu.vim
2460endif
2461
2462" Function called for testing all functions defined here.  These are
2463" script-local, thus need to be executed here.
2464" Returns a string with error messages (hopefully empty).
2465func! TestFiletypeFuncs(testlist)
2466  let output = ''
2467  for f in a:testlist
2468    try
2469      exe f
2470    catch
2471      let output = output . "\n" . f . ": " . v:exception
2472    endtry
2473  endfor
2474  return output
2475endfunc
2476
2477" Restore 'cpoptions'
2478let &cpo = s:cpo_save
2479unlet s:cpo_save
2480