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