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