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