xref: /vim-8.2.3635/runtime/filetype.vim (revision 18a1b9bd)
1" Vim support file to detect file types
2"
3" Maintainer:	Bram Moolenaar <[email protected]>
4" Last Change:	2012 Aug 02
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 (hg) commit file
1123au BufNewFile,BufRead hg-editor-*.txt		setf hgcommit
1124
1125" Mercurial config (looks like generic config file)
1126au BufNewFile,BufRead *.hgrc,*hgrc		setf cfg
1127
1128" Messages (logs mostly)
1129au 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
1130
1131" Metafont
1132au BufNewFile,BufRead *.mf			setf mf
1133
1134" MetaPost
1135au BufNewFile,BufRead *.mp			setf mp
1136
1137" MGL
1138au BufNewFile,BufRead *.mgl			setf mgl
1139
1140" MMIX or VMS makefile
1141au BufNewFile,BufRead *.mms			call s:FTmms()
1142
1143" Symbian meta-makefile definition (MMP)
1144au BufNewFile,BufRead *.mmp			setf mmp
1145
1146func! s:FTmms()
1147  let n = 1
1148  while n < 10
1149    let line = getline(n)
1150    if line =~ '^\s*\(%\|//\)' || line =~ '^\*'
1151      setf mmix
1152      return
1153    endif
1154    if line =~ '^\s*#'
1155      setf make
1156      return
1157    endif
1158    let n = n + 1
1159  endwhile
1160  setf mmix
1161endfunc
1162
1163
1164" Modsim III (or LambdaProlog)
1165au BufNewFile,BufRead *.mod
1166	\ if getline(1) =~ '\<module\>' |
1167	\   setf lprolog |
1168	\ else |
1169	\   setf modsim3 |
1170	\ endif
1171
1172" Modula 2
1173au BufNewFile,BufRead *.m2,*.DEF,*.MOD,*.md,*.mi setf modula2
1174
1175" Modula 3 (.m3, .i3, .mg, .ig)
1176au BufNewFile,BufRead *.[mi][3g]		setf modula3
1177
1178" Monk
1179au BufNewFile,BufRead *.isc,*.monk,*.ssc,*.tsc	setf monk
1180
1181" MOO
1182au BufNewFile,BufRead *.moo			setf moo
1183
1184" Modconf
1185au BufNewFile,BufRead */etc/modules.conf,*/etc/modules,*/etc/conf.modules setf modconf
1186
1187" Mplayer config
1188au BufNewFile,BufRead mplayer.conf,*/.mplayer/config	setf mplayerconf
1189
1190" Moterola S record
1191au BufNewFile,BufRead *.s19,*.s28,*.s37		setf srec
1192
1193" Mrxvtrc
1194au BufNewFile,BufRead mrxvtrc,.mrxvtrc		setf mrxvtrc
1195
1196" Msql
1197au BufNewFile,BufRead *.msql			setf msql
1198
1199" Mysql
1200au BufNewFile,BufRead *.mysql			setf mysql
1201
1202" Mutt setup files (must be before catch *.rc)
1203au BufNewFile,BufRead */etc/Muttrc.d/*		call s:StarSetf('muttrc')
1204
1205" M$ Resource files
1206au BufNewFile,BufRead *.rc,*.rch		setf rc
1207
1208" MuPAD source
1209au BufRead,BufNewFile *.mu			setf mupad
1210
1211" Mush
1212au BufNewFile,BufRead *.mush			setf mush
1213
1214" Mutt setup file (also for Muttng)
1215au BufNewFile,BufRead Mutt{ng,}rc		setf muttrc
1216
1217" Nano
1218au BufNewFile,BufRead */etc/nanorc,.nanorc	setf nanorc
1219
1220" Nastran input/DMAP
1221"au BufNewFile,BufRead *.dat			setf nastran
1222
1223" Natural
1224au BufNewFile,BufRead *.NS[ACGLMNPS]		setf natural
1225
1226" Netrc
1227au BufNewFile,BufRead .netrc			setf netrc
1228
1229" Ninja file
1230au BufNewFile,BufRead *.ninja			setf ninja
1231
1232" Novell netware batch files
1233au BufNewFile,BufRead *.ncf			setf ncf
1234
1235" Nroff/Troff (*.ms and *.t are checked below)
1236au BufNewFile,BufRead *.me
1237	\ if expand("<afile>") != "read.me" && expand("<afile>") != "click.me" |
1238	\   setf nroff |
1239	\ endif
1240au BufNewFile,BufRead *.tr,*.nr,*.roff,*.tmac,*.mom	setf nroff
1241au BufNewFile,BufRead *.[1-9]			call s:FTnroff()
1242
1243" This function checks if one of the first five lines start with a dot.  In
1244" that case it is probably an nroff file: 'filetype' is set and 1 is returned.
1245func! s:FTnroff()
1246  if getline(1)[0] . getline(2)[0] . getline(3)[0] . getline(4)[0] . getline(5)[0] =~ '\.'
1247    setf nroff
1248    return 1
1249  endif
1250  return 0
1251endfunc
1252
1253" Nroff or Objective C++
1254au BufNewFile,BufRead *.mm			call s:FTmm()
1255
1256func! s:FTmm()
1257  let n = 1
1258  while n < 10
1259    let line = getline(n)
1260    if line =~ '^\s*\(#\s*\(include\|import\)\>\|/\*\)'
1261      setf objcpp
1262      return
1263    endif
1264    let n = n + 1
1265  endwhile
1266  setf nroff
1267endfunc
1268
1269" Not Quite C
1270au BufNewFile,BufRead *.nqc			setf nqc
1271
1272" NSIS
1273au BufNewFile,BufRead *.nsi,*.nsh		setf nsis
1274
1275" OCAML
1276au BufNewFile,BufRead *.ml,*.mli,*.mll,*.mly,.ocamlinit	setf ocaml
1277
1278" Occam
1279au BufNewFile,BufRead *.occ			setf occam
1280
1281" Omnimark
1282au BufNewFile,BufRead *.xom,*.xin		setf omnimark
1283
1284" OpenROAD
1285au BufNewFile,BufRead *.or			setf openroad
1286
1287" OPL
1288au BufNewFile,BufRead *.[Oo][Pp][Ll]		setf opl
1289
1290" Oracle config file
1291au BufNewFile,BufRead *.ora			setf ora
1292
1293" Packet filter conf
1294au BufNewFile,BufRead pf.conf			setf pf
1295
1296" Pam conf
1297au BufNewFile,BufRead */etc/pam.conf		setf pamconf
1298
1299" PApp
1300au BufNewFile,BufRead *.papp,*.pxml,*.pxsl	setf papp
1301
1302" Password file
1303au 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
1304
1305" Pascal (also *.p)
1306au BufNewFile,BufRead *.pas			setf pascal
1307
1308" Delphi project file
1309au BufNewFile,BufRead *.dpr			setf pascal
1310
1311" PDF
1312au BufNewFile,BufRead *.pdf			setf pdf
1313
1314" Perl
1315if has("fname_case")
1316  au BufNewFile,BufRead *.pl,*.PL		call s:FTpl()
1317else
1318  au BufNewFile,BufRead *.pl			call s:FTpl()
1319endif
1320au BufNewFile,BufRead *.plx,*.al		setf perl
1321au BufNewFile,BufRead *.p6,*.pm6		setf perl6
1322
1323func! s:FTpl()
1324  if exists("g:filetype_pl")
1325    exe "setf " . g:filetype_pl
1326  else
1327    " recognize Prolog by specific text in the first non-empty line
1328    " require a blank after the '%' because Perl uses "%list" and "%translate"
1329    let l = getline(nextnonblank(1))
1330    if l =~ '\<prolog\>' || l =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || l =~ ':-'
1331      setf prolog
1332    else
1333      setf perl
1334    endif
1335  endif
1336endfunc
1337
1338" Perl, XPM or XPM2
1339au BufNewFile,BufRead *.pm
1340	\ if getline(1) =~ "XPM2" |
1341	\   setf xpm2 |
1342	\ elseif getline(1) =~ "XPM" |
1343	\   setf xpm |
1344	\ else |
1345	\   setf perl |
1346	\ endif
1347
1348" Perl POD
1349au BufNewFile,BufRead *.pod			setf pod
1350
1351" Php, php3, php4, etc.
1352" Also Phtml (was used for PHP 2 in the past)
1353" Also .ctp for Cake template file
1354au BufNewFile,BufRead *.php,*.php\d,*.phtml,*.ctp	setf php
1355
1356" Pike
1357au BufNewFile,BufRead *.pike,*.lpc,*.ulpc,*.pmod setf pike
1358
1359" Pinfo config
1360au BufNewFile,BufRead */etc/pinforc,*/.pinforc	setf pinfo
1361
1362" Palm Resource compiler
1363au BufNewFile,BufRead *.rcp			setf pilrc
1364
1365" Pine config
1366au BufNewFile,BufRead .pinerc,pinerc,.pinercex,pinercex		setf pine
1367
1368" PL/M (also: *.inp)
1369au BufNewFile,BufRead *.plm,*.p36,*.pac		setf plm
1370
1371" PL/SQL
1372au BufNewFile,BufRead *.pls,*.plsql		setf plsql
1373
1374" PLP
1375au BufNewFile,BufRead *.plp			setf plp
1376
1377" PO and PO template (GNU gettext)
1378au BufNewFile,BufRead *.po,*.pot		setf po
1379
1380" Postfix main config
1381au BufNewFile,BufRead main.cf			setf pfmain
1382
1383" PostScript (+ font files, encapsulated PostScript, Adobe Illustrator)
1384au BufNewFile,BufRead *.ps,*.pfa,*.afm,*.eps,*.epsf,*.epsi,*.ai	  setf postscr
1385
1386" PostScript Printer Description
1387au BufNewFile,BufRead *.ppd			setf ppd
1388
1389" Povray
1390au BufNewFile,BufRead *.pov			setf pov
1391
1392" Povray configuration
1393au BufNewFile,BufRead .povrayrc			setf povini
1394
1395" Povray, PHP or assembly
1396au BufNewFile,BufRead *.inc			call s:FTinc()
1397
1398func! s:FTinc()
1399  if exists("g:filetype_inc")
1400    exe "setf " . g:filetype_inc
1401  else
1402    let lines = getline(1).getline(2).getline(3)
1403    if lines =~? "perlscript"
1404      setf aspperl
1405    elseif lines =~ "<%"
1406      setf aspvbs
1407    elseif lines =~ "<?"
1408      setf php
1409    else
1410      call s:FTasmsyntax()
1411      if exists("b:asmsyntax")
1412	exe "setf " . fnameescape(b:asmsyntax)
1413      else
1414	setf pov
1415      endif
1416    endif
1417  endif
1418endfunc
1419
1420" Printcap and Termcap
1421au BufNewFile,BufRead *printcap
1422	\ let b:ptcap_type = "print" | setf ptcap
1423au BufNewFile,BufRead *termcap
1424	\ let b:ptcap_type = "term" | setf ptcap
1425
1426" PCCTS / ANTRL
1427"au BufNewFile,BufRead *.g			setf antrl
1428au BufNewFile,BufRead *.g			setf pccts
1429
1430" PPWizard
1431au BufNewFile,BufRead *.it,*.ih			setf ppwiz
1432
1433" Obj 3D file format
1434" TODO: is there a way to avoid MS-Windows Object files?
1435au BufNewFile,BufRead *.obj			setf obj
1436
1437" Oracle Pro*C/C++
1438au BufNewFile,BufRead *.pc			setf proc
1439
1440" Privoxy actions file
1441au BufNewFile,BufRead *.action			setf privoxy
1442
1443" Procmail
1444au BufNewFile,BufRead .procmail,.procmailrc	setf procmail
1445
1446" Progress or CWEB
1447au BufNewFile,BufRead *.w			call s:FTprogress_cweb()
1448
1449func! s:FTprogress_cweb()
1450  if exists("g:filetype_w")
1451    exe "setf " . g:filetype_w
1452    return
1453  endif
1454  if getline(1) =~ '&ANALYZE' || getline(3) =~ '&GLOBAL-DEFINE'
1455    setf progress
1456  else
1457    setf cweb
1458  endif
1459endfunc
1460
1461" Progress or assembly
1462au BufNewFile,BufRead *.i			call s:FTprogress_asm()
1463
1464func! s:FTprogress_asm()
1465  if exists("g:filetype_i")
1466    exe "setf " . g:filetype_i
1467    return
1468  endif
1469  " This function checks for an assembly comment the first ten lines.
1470  " If not found, assume Progress.
1471  let lnum = 1
1472  while lnum <= 10 && lnum < line('$')
1473    let line = getline(lnum)
1474    if line =~ '^\s*;' || line =~ '^\*'
1475      call s:FTasm()
1476      return
1477    elseif line !~ '^\s*$' || line =~ '^/\*'
1478      " Not an empty line: Doesn't look like valid assembly code.
1479      " Or it looks like a Progress /* comment
1480      break
1481    endif
1482    let lnum = lnum + 1
1483  endw
1484  setf progress
1485endfunc
1486
1487" Progress or Pascal
1488au BufNewFile,BufRead *.p			call s:FTprogress_pascal()
1489
1490func! s:FTprogress_pascal()
1491  if exists("g:filetype_p")
1492    exe "setf " . g:filetype_p
1493    return
1494  endif
1495  " This function checks for valid Pascal syntax in the first ten lines.
1496  " Look for either an opening comment or a program start.
1497  " If not found, assume Progress.
1498  let lnum = 1
1499  while lnum <= 10 && lnum < line('$')
1500    let line = getline(lnum)
1501    if line =~ '^\s*\(program\|unit\|procedure\|function\|const\|type\|var\)\>'
1502	\ || line =~ '^\s*{' || line =~ '^\s*(\*'
1503      setf pascal
1504      return
1505    elseif line !~ '^\s*$' || line =~ '^/\*'
1506      " Not an empty line: Doesn't look like valid Pascal code.
1507      " Or it looks like a Progress /* comment
1508      break
1509    endif
1510    let lnum = lnum + 1
1511  endw
1512  setf progress
1513endfunc
1514
1515
1516" Software Distributor Product Specification File (POSIX 1387.2-1995)
1517au BufNewFile,BufRead *.psf			setf psf
1518au BufNewFile,BufRead INDEX,INFO
1519	\ if getline(1) =~ '^\s*\(distribution\|installed_software\|root\|bundle\|product\)\s*$' |
1520	\   setf psf |
1521	\ endif
1522
1523" Prolog
1524au BufNewFile,BufRead *.pdb			setf prolog
1525
1526" Promela
1527au BufNewFile,BufRead *.pml			setf promela
1528
1529" Protocols
1530au BufNewFile,BufRead */etc/protocols		setf protocols
1531
1532" Pyrex
1533au BufNewFile,BufRead *.pyx,*.pxd		setf pyrex
1534
1535" Python
1536au BufNewFile,BufRead *.py,*.pyw		setf python
1537
1538" Quixote (Python-based web framework)
1539au BufNewFile,BufRead *.ptl			setf python
1540
1541" Radiance
1542au BufNewFile,BufRead *.rad,*.mat		setf radiance
1543
1544" Ratpoison config/command files
1545au BufNewFile,BufRead .ratpoisonrc,ratpoisonrc	setf ratpoison
1546
1547" RCS file
1548au BufNewFile,BufRead *\,v			setf rcs
1549
1550" Readline
1551au BufNewFile,BufRead .inputrc,inputrc		setf readline
1552
1553" Registry for MS-Windows
1554au BufNewFile,BufRead *.reg
1555	\ if getline(1) =~? '^REGEDIT[0-9]*\s*$\|^Windows Registry Editor Version \d*\.\d*\s*$' | setf registry | endif
1556
1557" Renderman Interface Bytestream
1558au BufNewFile,BufRead *.rib			setf rib
1559
1560" Rexx
1561au BufNewFile,BufRead *.rexx,*.rex,*.jrexx,*.rxj,*.orx	setf rexx
1562
1563" R (Splus)
1564if has("fname_case")
1565  au BufNewFile,BufRead *.s,*.S			setf r
1566else
1567  au BufNewFile,BufRead *.s			setf r
1568endif
1569
1570" R Help file
1571if has("fname_case")
1572  au BufNewFile,BufRead *.rd,*.Rd		setf rhelp
1573else
1574  au BufNewFile,BufRead *.rd			setf rhelp
1575endif
1576
1577" R noweb file
1578if has("fname_case")
1579  au BufNewFile,BufRead *.Rnw,*.rnw,*.Snw,*.snw		setf rnoweb
1580else
1581  au BufNewFile,BufRead *.rnw,*.snw			setf rnoweb
1582endif
1583
1584" Rexx, Rebol or R
1585au BufNewFile,BufRead *.r,*.R			call s:FTr()
1586
1587func! s:FTr()
1588  let max = line("$") > 50 ? 50 : line("$")
1589
1590  for n in range(1, max)
1591    " Rebol is easy to recognize, check for that first
1592    if getline(n) =~? '\<REBOL\>'
1593      setf rebol
1594      return
1595    endif
1596  endfor
1597
1598  for n in range(1, max)
1599    " R has # comments
1600    if getline(n) =~ '^\s*#'
1601      setf r
1602      return
1603    endif
1604    " Rexx has /* comments */
1605    if getline(n) =~ '^\s*/\*'
1606      setf rexx
1607      return
1608    endif
1609  endfor
1610
1611  " Nothing recognized, use user default or assume Rexx
1612  if exists("g:filetype_r")
1613    exe "setf " . g:filetype_r
1614  else
1615    " Rexx used to be the default, but R appears to be much more popular.
1616    setf r
1617  endif
1618endfunc
1619
1620" Remind
1621au BufNewFile,BufRead .reminders,*.remind,*.rem		setf remind
1622
1623" Resolv.conf
1624au BufNewFile,BufRead resolv.conf		setf resolv
1625
1626" Relax NG Compact
1627au BufNewFile,BufRead *.rnc			setf rnc
1628
1629" RPL/2
1630au BufNewFile,BufRead *.rpl			setf rpl
1631
1632" Robots.txt
1633au BufNewFile,BufRead robots.txt		setf robots
1634
1635" Rpcgen
1636au BufNewFile,BufRead *.x			setf rpcgen
1637
1638" reStructuredText Documentation Format
1639au BufNewFile,BufRead *.rst			setf rst
1640
1641" RTF
1642au BufNewFile,BufRead *.rtf			setf rtf
1643
1644" Interactive Ruby shell
1645au BufNewFile,BufRead .irbrc,irbrc		setf ruby
1646
1647" Ruby
1648au BufNewFile,BufRead *.rb,*.rbw		setf ruby
1649
1650" RubyGems
1651au BufNewFile,BufRead *.gemspec			setf ruby
1652
1653" Rackup
1654au BufNewFile,BufRead *.ru			setf ruby
1655
1656" Bundler
1657au BufNewFile,BufRead Gemfile			setf ruby
1658
1659" Ruby on Rails
1660au BufNewFile,BufRead *.builder,*.rxml,*.rjs	setf ruby
1661
1662" Rantfile and Rakefile is like Ruby
1663au BufNewFile,BufRead [rR]antfile,*.rant,[rR]akefile,*.rake	setf ruby
1664
1665" S-lang (or shader language, or SmallLisp)
1666au BufNewFile,BufRead *.sl			setf slang
1667
1668" Samba config
1669au BufNewFile,BufRead smb.conf			setf samba
1670
1671" SAS script
1672au BufNewFile,BufRead *.sas			setf sas
1673
1674" Sass
1675au BufNewFile,BufRead *.sass			setf sass
1676
1677" Sather
1678au BufNewFile,BufRead *.sa			setf sather
1679
1680" Scilab
1681au BufNewFile,BufRead *.sci,*.sce		setf scilab
1682
1683" SCSS
1684au BufNewFile,BufRead *.scss			setf scss
1685
1686" SD: Streaming Descriptors
1687au BufNewFile,BufRead *.sd			setf sd
1688
1689" SDL
1690au BufNewFile,BufRead *.sdl,*.pr		setf sdl
1691
1692" sed
1693au BufNewFile,BufRead *.sed			setf sed
1694
1695" Sieve (RFC 3028)
1696au BufNewFile,BufRead *.siv			setf sieve
1697
1698" Sendmail
1699au BufNewFile,BufRead sendmail.cf		setf sm
1700
1701" Sendmail .mc files are actually m4.  Could also be MS Message text file.
1702au BufNewFile,BufRead *.mc			call s:McSetf()
1703
1704func! s:McSetf()
1705  " Rely on the file to start with a comment.
1706  " MS message text files use ';', Sendmail files use '#' or 'dnl'
1707  for lnum in range(1, min([line("$"), 20]))
1708    let line = getline(lnum)
1709    if line =~ '^\s*\(#\|dnl\)'
1710      setf m4  " Sendmail .mc file
1711      return
1712    elseif line =~ '^\s*;'
1713      setf msmessages  " MS Message text file
1714      return
1715    endif
1716  endfor
1717  setf m4  " Default: Sendmail .mc file
1718endfunc
1719
1720" Services
1721au BufNewFile,BufRead */etc/services		setf services
1722
1723" Service Location config
1724au BufNewFile,BufRead */etc/slp.conf		setf slpconf
1725
1726" Service Location registration
1727au BufNewFile,BufRead */etc/slp.reg		setf slpreg
1728
1729" Service Location SPI
1730au BufNewFile,BufRead */etc/slp.spi		setf slpspi
1731
1732" Setserial config
1733au BufNewFile,BufRead */etc/serial.conf		setf setserial
1734
1735" SGML
1736au BufNewFile,BufRead *.sgm,*.sgml
1737	\ if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'linuxdoc' |
1738	\   setf sgmllnx |
1739	\ elseif getline(1) =~ '<!DOCTYPE.*DocBook' || getline(2) =~ '<!DOCTYPE.*DocBook' |
1740	\   let b:docbk_type="sgml" |
1741	\   setf docbk |
1742	\ else |
1743	\   setf sgml |
1744	\ endif
1745
1746" SGMLDECL
1747au BufNewFile,BufRead *.decl,*.dcl,*.dec
1748	\ if getline(1).getline(2).getline(3) =~? '^<!SGML' |
1749	\    setf sgmldecl |
1750	\ endif
1751
1752" SGML catalog file
1753au BufNewFile,BufRead catalog			setf catalog
1754au BufNewFile,BufRead sgml.catalog*		call s:StarSetf('catalog')
1755
1756" Shell scripts (sh, ksh, bash, bash2, csh); Allow .profile_foo etc.
1757" Gentoo ebuilds are actually bash scripts
1758au BufNewFile,BufRead .bashrc*,bashrc,bash.bashrc,.bash_profile*,.bash_logout*,*.bash,*.ebuild call SetFileTypeSH("bash")
1759au BufNewFile,BufRead .kshrc*,*.ksh call SetFileTypeSH("ksh")
1760au BufNewFile,BufRead */etc/profile,.profile*,*.sh,*.env call SetFileTypeSH(getline(1))
1761
1762" Also called from scripts.vim.
1763func! SetFileTypeSH(name)
1764  if expand("<amatch>") =~ g:ft_ignore_pat
1765    return
1766  endif
1767  if a:name =~ '\<csh\>'
1768    " Some .sh scripts contain #!/bin/csh.
1769    call SetFileTypeShell("csh")
1770    return
1771  elseif a:name =~ '\<tcsh\>'
1772    " Some .sh scripts contain #!/bin/tcsh.
1773    call SetFileTypeShell("tcsh")
1774    return
1775  elseif a:name =~ '\<ksh\>'
1776    let b:is_kornshell = 1
1777    if exists("b:is_bash")
1778      unlet b:is_bash
1779    endif
1780    if exists("b:is_sh")
1781      unlet b:is_sh
1782    endif
1783  elseif exists("g:bash_is_sh") || a:name =~ '\<bash\>' || a:name =~ '\<bash2\>'
1784    let b:is_bash = 1
1785    if exists("b:is_kornshell")
1786      unlet b:is_kornshell
1787    endif
1788    if exists("b:is_sh")
1789      unlet b:is_sh
1790    endif
1791  elseif a:name =~ '\<sh\>'
1792    let b:is_sh = 1
1793    if exists("b:is_kornshell")
1794      unlet b:is_kornshell
1795    endif
1796    if exists("b:is_bash")
1797      unlet b:is_bash
1798    endif
1799  endif
1800  call SetFileTypeShell("sh")
1801endfunc
1802
1803" For shell-like file types, check for an "exec" command hidden in a comment,
1804" as used for Tcl.
1805" Also called from scripts.vim, thus can't be local to this script.
1806func! SetFileTypeShell(name)
1807  if expand("<amatch>") =~ g:ft_ignore_pat
1808    return
1809  endif
1810  let l = 2
1811  while l < 20 && l < line("$") && getline(l) =~ '^\s*\(#\|$\)'
1812    " Skip empty and comment lines.
1813    let l = l + 1
1814  endwhile
1815  if l < line("$") && getline(l) =~ '\s*exec\s' && getline(l - 1) =~ '^\s*#.*\\$'
1816    " Found an "exec" line after a comment with continuation
1817    let n = substitute(getline(l),'\s*exec\s\+\([^ ]*/\)\=', '', '')
1818    if n =~ '\<tclsh\|\<wish'
1819      setf tcl
1820      return
1821    endif
1822  endif
1823  exe "setf " . a:name
1824endfunc
1825
1826" tcsh scripts
1827au BufNewFile,BufRead .tcshrc*,*.tcsh,tcsh.tcshrc,tcsh.login	call SetFileTypeShell("tcsh")
1828
1829" csh scripts, but might also be tcsh scripts (on some systems csh is tcsh)
1830au BufNewFile,BufRead .login*,.cshrc*,csh.cshrc,csh.login,csh.logout,*.csh,.alias  call s:CSH()
1831
1832func! s:CSH()
1833  if exists("g:filetype_csh")
1834    call SetFileTypeShell(g:filetype_csh)
1835  elseif &shell =~ "tcsh"
1836    call SetFileTypeShell("tcsh")
1837  else
1838    call SetFileTypeShell("csh")
1839  endif
1840endfunc
1841
1842" Z-Shell script
1843au BufNewFile,BufRead .zprofile,*/etc/zprofile,.zfbfmarks  setf zsh
1844au BufNewFile,BufRead .zsh*,.zlog*,.zcompdump*  call s:StarSetf('zsh')
1845au BufNewFile,BufRead *.zsh			setf zsh
1846
1847" Scheme
1848au BufNewFile,BufRead *.scm,*.ss,*.rkt		setf scheme
1849
1850" Screen RC
1851au BufNewFile,BufRead .screenrc,screenrc	setf screen
1852
1853" Simula
1854au BufNewFile,BufRead *.sim			setf simula
1855
1856" SINDA
1857au BufNewFile,BufRead *.sin,*.s85		setf sinda
1858
1859" SiSU
1860au BufNewFile,BufRead *.sst,*.ssm,*.ssi,*.-sst,*._sst setf sisu
1861au BufNewFile,BufRead *.sst.meta,*.-sst.meta,*._sst.meta setf sisu
1862
1863" SKILL
1864au BufNewFile,BufRead *.il,*.ils,*.cdf		setf skill
1865
1866" SLRN
1867au BufNewFile,BufRead .slrnrc			setf slrnrc
1868au BufNewFile,BufRead *.score			setf slrnsc
1869
1870" Smalltalk (and TeX)
1871au BufNewFile,BufRead *.st			setf st
1872au BufNewFile,BufRead *.cls
1873	\ if getline(1) =~ '^%' |
1874	\  setf tex |
1875	\ else |
1876	\  setf st |
1877	\ endif
1878
1879" Smarty templates
1880au BufNewFile,BufRead *.tpl			setf smarty
1881
1882" SMIL or XML
1883au BufNewFile,BufRead *.smil
1884	\ if getline(1) =~ '<?\s*xml.*?>' |
1885	\   setf xml |
1886	\ else |
1887	\   setf smil |
1888	\ endif
1889
1890" SMIL or SNMP MIB file
1891au BufNewFile,BufRead *.smi
1892	\ if getline(1) =~ '\<smil\>' |
1893	\   setf smil |
1894	\ else |
1895	\   setf mib |
1896	\ endif
1897
1898" SMITH
1899au BufNewFile,BufRead *.smt,*.smith		setf smith
1900
1901" Snobol4 and spitbol
1902au BufNewFile,BufRead *.sno,*.spt		setf snobol4
1903
1904" SNMP MIB files
1905au BufNewFile,BufRead *.mib,*.my		setf mib
1906
1907" Snort Configuration
1908au BufNewFile,BufRead *.hog,snort.conf,vision.conf	setf hog
1909au BufNewFile,BufRead *.rules			call s:FTRules()
1910
1911let s:ft_rules_udev_rules_pattern = '^\s*\cudev_rules\s*=\s*"\([^"]\{-1,}\)/*".*'
1912func! s:FTRules()
1913  let path = expand('<amatch>:p')
1914  if path =~ '^/\(etc/udev/\%(rules\.d/\)\=.*\.rules\|lib/udev/\%(rules\.d/\)\=.*\.rules\)$'
1915    setf udevrules
1916    return
1917  endif
1918  if path =~ '^/etc/ufw/'
1919    setf conf  " Better than hog
1920    return
1921  endif
1922  try
1923    let config_lines = readfile('/etc/udev/udev.conf')
1924  catch /^Vim\%((\a\+)\)\=:E484/
1925    setf hog
1926    return
1927  endtry
1928  let dir = expand('<amatch>:p:h')
1929  for line in config_lines
1930    if line =~ s:ft_rules_udev_rules_pattern
1931      let udev_rules = substitute(line, s:ft_rules_udev_rules_pattern, '\1', "")
1932      if dir == udev_rules
1933        setf udevrules
1934      endif
1935      break
1936    endif
1937  endfor
1938  setf hog
1939endfunc
1940
1941
1942" Spec (Linux RPM)
1943au BufNewFile,BufRead *.spec			setf spec
1944
1945" Speedup (AspenTech plant simulator)
1946au BufNewFile,BufRead *.speedup,*.spdata,*.spd	setf spup
1947
1948" Slice
1949au BufNewFile,BufRead *.ice			setf slice
1950
1951" Spice
1952au BufNewFile,BufRead *.sp,*.spice		setf spice
1953
1954" Spyce
1955au BufNewFile,BufRead *.spy,*.spi		setf spyce
1956
1957" Squid
1958au BufNewFile,BufRead squid.conf		setf squid
1959
1960" SQL for Oracle Designer
1961au BufNewFile,BufRead *.tyb,*.typ,*.tyc,*.pkb,*.pks	setf sql
1962
1963" SQL
1964au BufNewFile,BufRead *.sql			call s:SQL()
1965
1966func! s:SQL()
1967  if exists("g:filetype_sql")
1968    exe "setf " . g:filetype_sql
1969  else
1970    setf sql
1971  endif
1972endfunc
1973
1974" SQLJ
1975au BufNewFile,BufRead *.sqlj			setf sqlj
1976
1977" SQR
1978au BufNewFile,BufRead *.sqr,*.sqi		setf sqr
1979
1980" OpenSSH configuration
1981au BufNewFile,BufRead ssh_config,*/.ssh/config	setf sshconfig
1982
1983" OpenSSH server configuration
1984au BufNewFile,BufRead sshd_config		setf sshdconfig
1985
1986" Stata
1987au BufNewFile,BufRead *.ado,*.class,*.do,*.imata,*.mata   setf stata
1988
1989" SMCL
1990au BufNewFile,BufRead *.hlp,*.ihlp,*.smcl	setf smcl
1991
1992" Stored Procedures
1993au BufNewFile,BufRead *.stp			setf stp
1994
1995" Standard ML
1996au BufNewFile,BufRead *.sml			setf sml
1997
1998" Sratus VOS command macro
1999au BufNewFile,BufRead *.cm			setf voscm
2000
2001" Sysctl
2002au BufNewFile,BufRead */etc/sysctl.conf,*/etc/sysctl.d/*.conf	setf sysctl
2003
2004" Synopsys Design Constraints
2005au BufNewFile,BufRead *.sdc			setf sdc
2006
2007" Sudoers
2008au BufNewFile,BufRead */etc/sudoers,sudoers.tmp	setf sudoers
2009
2010" SVG (Scalable Vector Graphics)
2011au BufNewFile,BufRead *.svg			setf svg
2012
2013" If the file has an extension of 't' and is in a directory 't' then it is
2014" almost certainly a Perl test file.
2015" If the first line starts with '#' and contains 'perl' it's probably a Perl
2016" file.
2017" (Slow test) If a file contains a 'use' statement then it is almost certainly
2018" a Perl file.
2019func! s:FTperl()
2020  if expand("%:e") == 't' && expand("%:p:h:t") == 't'
2021    setf perl
2022    return 1
2023  endif
2024  if getline(1)[0] == '#' && getline(1) =~ 'perl'
2025    setf perl
2026    return 1
2027  endif
2028  if search('^use\s\s*\k', 'nc', 30)
2029    setf perl
2030    return 1
2031  endif
2032  return 0
2033endfunc
2034
2035" Tads (or Nroff or Perl test file)
2036au BufNewFile,BufRead *.t
2037	\ if !s:FTnroff() && !s:FTperl() | setf tads | endif
2038
2039" Tags
2040au BufNewFile,BufRead tags			setf tags
2041
2042" TAK
2043au BufNewFile,BufRead *.tak			setf tak
2044
2045" Task
2046au BufRead,BufNewFile {pending,completed,undo}.data  setf taskdata
2047au BufRead,BufNewFile *.task                    setf taskedit
2048
2049" Tcl (JACL too)
2050au BufNewFile,BufRead *.tcl,*.tk,*.itcl,*.itk,*.jacl	setf tcl
2051
2052" TealInfo
2053au BufNewFile,BufRead *.tli			setf tli
2054
2055" Telix Salt
2056au BufNewFile,BufRead *.slt			setf tsalt
2057
2058" Terminfo
2059au BufNewFile,BufRead *.ti			setf terminfo
2060
2061" TeX
2062au BufNewFile,BufRead *.latex,*.sty,*.dtx,*.ltx,*.bbl	setf tex
2063au BufNewFile,BufRead *.tex			call s:FTtex()
2064
2065" Choose context, plaintex, or tex (LaTeX) based on these rules:
2066" 1. Check the first line of the file for "%&<format>".
2067" 2. Check the first 1000 non-comment lines for LaTeX or ConTeXt keywords.
2068" 3. Default to "latex" or to g:tex_flavor, can be set in user's vimrc.
2069func! s:FTtex()
2070  let firstline = getline(1)
2071  if firstline =~ '^%&\s*\a\+'
2072    let format = tolower(matchstr(firstline, '\a\+'))
2073    let format = substitute(format, 'pdf', '', '')
2074    if format == 'tex'
2075      let format = 'plain'
2076    endif
2077  else
2078    " Default value, may be changed later:
2079    let format = exists("g:tex_flavor") ? g:tex_flavor : 'plain'
2080    " Save position, go to the top of the file, find first non-comment line.
2081    let save_cursor = getpos('.')
2082    call cursor(1,1)
2083    let firstNC = search('^\s*[^[:space:]%]', 'c', 1000)
2084    if firstNC " Check the next thousand lines for a LaTeX or ConTeXt keyword.
2085      let lpat = 'documentclass\>\|usepackage\>\|begin{\|newcommand\>\|renewcommand\>'
2086      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\>'
2087      let kwline = search('^\s*\\\%(' . lpat . '\)\|^\s*\\\(' . cpat . '\)',
2088			      \ 'cnp', firstNC + 1000)
2089      if kwline == 1	" lpat matched
2090	let format = 'latex'
2091      elseif kwline == 2	" cpat matched
2092	let format = 'context'
2093      endif		" If neither matched, keep default set above.
2094      " let lline = search('^\s*\\\%(' . lpat . '\)', 'cn', firstNC + 1000)
2095      " let cline = search('^\s*\\\%(' . cpat . '\)', 'cn', firstNC + 1000)
2096      " if cline > 0
2097      "   let format = 'context'
2098      " endif
2099      " if lline > 0 && (cline == 0 || cline > lline)
2100      "   let format = 'tex'
2101      " endif
2102    endif " firstNC
2103    call setpos('.', save_cursor)
2104  endif " firstline =~ '^%&\s*\a\+'
2105
2106  " Translation from formats to file types.  TODO:  add AMSTeX, RevTex, others?
2107  if format == 'plain'
2108    setf plaintex
2109  elseif format == 'context'
2110    setf context
2111  else " probably LaTeX
2112    setf tex
2113  endif
2114  return
2115endfunc
2116
2117" ConTeXt
2118au BufNewFile,BufRead tex/context/*/*.tex,*.mkii,*.mkiv   setf context
2119
2120" Texinfo
2121au BufNewFile,BufRead *.texinfo,*.texi,*.txi	setf texinfo
2122
2123" TeX configuration
2124au BufNewFile,BufRead texmf.cnf			setf texmf
2125
2126" Tidy config
2127au BufNewFile,BufRead .tidyrc,tidyrc		setf tidy
2128
2129" TF mud client
2130au BufNewFile,BufRead *.tf,.tfrc,tfrc		setf tf
2131
2132" TPP - Text Presentation Program
2133au BufNewFile,BufReadPost *.tpp			setf tpp
2134
2135" Treetop
2136au BufRead,BufNewFile *.treetop			setf treetop
2137
2138" Trustees
2139au BufNewFile,BufRead trustees.conf		setf trustees
2140
2141" TSS - Geometry
2142au BufNewFile,BufReadPost *.tssgm		setf tssgm
2143
2144" TSS - Optics
2145au BufNewFile,BufReadPost *.tssop		setf tssop
2146
2147" TSS - Command Line (temporary)
2148au BufNewFile,BufReadPost *.tsscl		setf tsscl
2149
2150" TWIG files
2151au BufNewFile,BufReadPost *.twig		setf twig
2152
2153" Motif UIT/UIL files
2154au BufNewFile,BufRead *.uit,*.uil		setf uil
2155
2156" Udev conf
2157au BufNewFile,BufRead */etc/udev/udev.conf	setf udevconf
2158
2159" Udev permissions
2160au BufNewFile,BufRead */etc/udev/permissions.d/*.permissions setf udevperm
2161"
2162" Udev symlinks config
2163au BufNewFile,BufRead */etc/udev/cdsymlinks.conf	setf sh
2164
2165" UnrealScript
2166au BufNewFile,BufRead *.uc			setf uc
2167
2168" Updatedb
2169au BufNewFile,BufRead */etc/updatedb.conf	setf updatedb
2170
2171" Upstart (init(8)) config files
2172au BufNewFile,BufRead */etc/init/*.conf,*/.init/*.conf          setf upstart
2173au BufNewFile,BufRead */etc/init/*.override,*/.init/*.override  setf upstart
2174
2175" Vera
2176au BufNewFile,BufRead *.vr,*.vri,*.vrh		setf vera
2177
2178" Verilog HDL
2179au BufNewFile,BufRead *.v			setf verilog
2180
2181" Verilog-AMS HDL
2182au BufNewFile,BufRead *.va,*.vams		setf verilogams
2183
2184" VHDL
2185au BufNewFile,BufRead *.hdl,*.vhd,*.vhdl,*.vbe,*.vst  setf vhdl
2186au BufNewFile,BufRead *.vhdl_[0-9]*		call s:StarSetf('vhdl')
2187
2188" Vim script
2189au BufNewFile,BufRead *.vim,*.vba,.exrc,_exrc	setf vim
2190
2191" Viminfo file
2192au BufNewFile,BufRead .viminfo,_viminfo		setf viminfo
2193
2194" Virata Config Script File or Drupal module
2195au BufRead,BufNewFile *.hw,*.module,*.pkg
2196	\ if getline(1) =~ '<?php' |
2197	\   setf php |
2198	\ else |
2199	\   setf virata |
2200	\ endif
2201
2202" Visual Basic (also uses *.bas) or FORM
2203au BufNewFile,BufRead *.frm			call s:FTVB("form")
2204
2205" SaxBasic is close to Visual Basic
2206au BufNewFile,BufRead *.sba			setf vb
2207
2208" Vgrindefs file
2209au BufNewFile,BufRead vgrindefs			setf vgrindefs
2210
2211" VRML V1.0c
2212au BufNewFile,BufRead *.wrl			setf vrml
2213
2214" Webmacro
2215au BufNewFile,BufRead *.wm			setf webmacro
2216
2217" Wget config
2218au BufNewFile,BufRead .wgetrc,wgetrc		setf wget
2219
2220" Website MetaLanguage
2221au BufNewFile,BufRead *.wml			setf wml
2222
2223" Winbatch
2224au BufNewFile,BufRead *.wbt			setf winbatch
2225
2226" WSML
2227au BufNewFile,BufRead *.wsml			setf wsml
2228
2229" WvDial
2230au BufNewFile,BufRead wvdial.conf,.wvdialrc	setf wvdial
2231
2232" CVS RC file
2233au BufNewFile,BufRead .cvsrc			setf cvsrc
2234
2235" CVS commit file
2236au BufNewFile,BufRead cvs\d\+			setf cvs
2237
2238" WEB (*.web is also used for Winbatch: Guess, based on expecting "%" comment
2239" lines in a WEB file).
2240au BufNewFile,BufRead *.web
2241	\ if getline(1)[0].getline(2)[0].getline(3)[0].getline(4)[0].getline(5)[0] =~ "%" |
2242	\   setf web |
2243	\ else |
2244	\   setf winbatch |
2245	\ endif
2246
2247" Windows Scripting Host and Windows Script Component
2248au BufNewFile,BufRead *.ws[fc]			setf wsh
2249
2250" XHTML
2251au BufNewFile,BufRead *.xhtml,*.xht		setf xhtml
2252
2253" X Pixmap (dynamically sets colors, use BufEnter to make it work better)
2254au BufEnter *.xpm
2255	\ if getline(1) =~ "XPM2" |
2256	\   setf xpm2 |
2257	\ else |
2258	\   setf xpm |
2259	\ endif
2260au BufEnter *.xpm2				setf xpm2
2261
2262" XFree86 config
2263au BufNewFile,BufRead XF86Config
2264	\ if getline(1) =~ '\<XConfigurator\>' |
2265	\   let b:xf86conf_xfree86_version = 3 |
2266	\ endif |
2267	\ setf xf86conf
2268au BufNewFile,BufRead */xorg.conf.d/*.conf
2269	\ let b:xf86conf_xfree86_version = 4 |
2270	\ setf xf86conf
2271
2272" Xorg config
2273au BufNewFile,BufRead xorg.conf,xorg.conf-4	let b:xf86conf_xfree86_version = 4 | setf xf86conf
2274
2275" Xinetd conf
2276au BufNewFile,BufRead */etc/xinetd.conf		setf xinetd
2277
2278" XS Perl extension interface language
2279au BufNewFile,BufRead *.xs			setf xs
2280
2281" X resources file
2282au BufNewFile,BufRead .Xdefaults,.Xpdefaults,.Xresources,xdm-config,*.ad setf xdefaults
2283
2284" Xmath
2285au BufNewFile,BufRead *.msc,*.msf		setf xmath
2286au BufNewFile,BufRead *.ms
2287	\ if !s:FTnroff() | setf xmath | endif
2288
2289" XML  specific variants: docbk and xbl
2290au BufNewFile,BufRead *.xml			call s:FTxml()
2291
2292func! s:FTxml()
2293  let n = 1
2294  while n < 100 && n < line("$")
2295    let line = getline(n)
2296    if line =~ '<!DOCTYPE.*DocBook'
2297      let b:docbk_type = "xml"
2298      setf docbk
2299      return
2300    endif
2301    if line =~ 'xmlns:xbl="http://www.mozilla.org/xbl"'
2302      setf xbl
2303      return
2304    endif
2305    let n += 1
2306  endwhile
2307  setf xml
2308endfunc
2309
2310" XMI (holding UML models) is also XML
2311au BufNewFile,BufRead *.xmi			setf xml
2312
2313" CSPROJ files are Visual Studio.NET's XML-based project config files
2314au BufNewFile,BufRead *.csproj,*.csproj.user	setf xml
2315
2316" Qt Linguist translation source and Qt User Interface Files are XML
2317au BufNewFile,BufRead *.ts,*.ui			setf xml
2318
2319" TPM's are RDF-based descriptions of TeX packages (Nikolai Weibull)
2320au BufNewFile,BufRead *.tpm			setf xml
2321
2322" Xdg menus
2323au BufNewFile,BufRead */etc/xdg/menus/*.menu	setf xml
2324
2325" ATI graphics driver configuration
2326au BufNewFile,BufRead fglrxrc			setf xml
2327
2328" XLIFF (XML Localisation Interchange File Format) is also XML
2329au BufNewFile,BufRead *.xlf			setf xml
2330au BufNewFile,BufRead *.xliff			setf xml
2331
2332" XML User Interface Language
2333au BufNewFile,BufRead *.xul			setf xml
2334
2335" X11 xmodmap (also see below)
2336au BufNewFile,BufRead *Xmodmap			setf xmodmap
2337
2338" Xquery
2339au BufNewFile,BufRead *.xq,*.xql,*.xqm,*.xquery,*.xqy	setf xquery
2340
2341" XSD
2342au BufNewFile,BufRead *.xsd			setf xsd
2343
2344" Xslt
2345au BufNewFile,BufRead *.xsl,*.xslt		setf xslt
2346
2347" Yacc
2348au BufNewFile,BufRead *.yy			setf yacc
2349
2350" Yacc or racc
2351au BufNewFile,BufRead *.y			call s:FTy()
2352
2353func! s:FTy()
2354  let n = 1
2355  while n < 100 && n < line("$")
2356    let line = getline(n)
2357    if line =~ '^\s*%'
2358      setf yacc
2359      return
2360    endif
2361    if getline(n) =~ '^\s*\(#\|class\>\)' && getline(n) !~ '^\s*#\s*include'
2362      setf racc
2363      return
2364    endif
2365    let n = n + 1
2366  endwhile
2367  setf yacc
2368endfunc
2369
2370
2371" Yaml
2372au BufNewFile,BufRead *.yaml,*.yml		setf yaml
2373
2374" yum conf (close enough to dosini)
2375au BufNewFile,BufRead */etc/yum.conf 		setf dosini
2376
2377" Zimbu
2378au BufNewFile,BufRead *.zu 			setf zimbu
2379
2380" Zope
2381"   dtml (zope dynamic template markup language), pt (zope page template),
2382"   cpt (zope form controller page template)
2383au BufNewFile,BufRead *.dtml,*.pt,*.cpt		call s:FThtml()
2384"   zsql (zope sql method)
2385au BufNewFile,BufRead *.zsql			call s:SQL()
2386
2387" Z80 assembler asz80
2388au BufNewFile,BufRead *.z8a			setf z8a
2389
2390augroup END
2391
2392
2393" Source the user-specified filetype file, for backwards compatibility with
2394" Vim 5.x.
2395if exists("myfiletypefile") && filereadable(expand(myfiletypefile))
2396  execute "source " . myfiletypefile
2397endif
2398
2399
2400" Check for "*" after loading myfiletypefile, so that scripts.vim is only used
2401" when there are no matching file name extensions.
2402" Don't do this for compressed files.
2403augroup filetypedetect
2404au BufNewFile,BufRead *
2405	\ if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat
2406	\ | runtime! scripts.vim | endif
2407au StdinReadPost * if !did_filetype() | runtime! scripts.vim | endif
2408
2409
2410" Extra checks for when no filetype has been detected now.  Mostly used for
2411" patterns that end in "*".  E.g., "zsh*" matches "zsh.vim", but that's a Vim
2412" script file.
2413" Most of these should call s:StarSetf() to avoid names ending in .gz and the
2414" like are used.
2415
2416" More Apache config files
2417au BufNewFile,BufRead access.conf*,apache.conf*,apache2.conf*,httpd.conf*,srm.conf*	call s:StarSetf('apache')
2418au BufNewFile,BufRead */etc/apache2/*.conf*,*/etc/apache2/conf.*/*,*/etc/apache2/mods-*/*,*/etc/apache2/sites-*/*,*/etc/httpd/conf.d/*.conf*		call s:StarSetf('apache')
2419
2420" Asterisk config file
2421au BufNewFile,BufRead *asterisk/*.conf*		call s:StarSetf('asterisk')
2422au BufNewFile,BufRead *asterisk*/*voicemail.conf* call s:StarSetf('asteriskvm')
2423
2424" Bazaar version control
2425au BufNewFile,BufRead bzr_log.*			setf bzr
2426
2427" BIND zone
2428au BufNewFile,BufRead */named/db.*,*/bind/db.*	call s:StarSetf('bindzone')
2429
2430" Calendar
2431au BufNewFile,BufRead */.calendar/*,
2432	\*/share/calendar/*/calendar.*,*/share/calendar/calendar.*
2433	\					call s:StarSetf('calendar')
2434
2435" Changelog
2436au BufNewFile,BufRead [cC]hange[lL]og*
2437	\ if getline(1) =~ '; urgency='
2438	\|  call s:StarSetf('debchangelog')
2439	\|else
2440	\|  call s:StarSetf('changelog')
2441	\|endif
2442
2443" Crontab
2444au BufNewFile,BufRead crontab,crontab.*,*/etc/cron.d/*		call s:StarSetf('crontab')
2445
2446" dnsmasq(8) configuration
2447au BufNewFile,BufRead */etc/dnsmasq.d/*		call s:StarSetf('dnsmasq')
2448
2449" Dracula
2450au BufNewFile,BufRead drac.*			call s:StarSetf('dracula')
2451
2452" Fvwm
2453au BufNewFile,BufRead */.fvwm/*			call s:StarSetf('fvwm')
2454au BufNewFile,BufRead *fvwmrc*,*fvwm95*.hook
2455	\ let b:fvwm_version = 1 | call s:StarSetf('fvwm')
2456au BufNewFile,BufRead *fvwm2rc*
2457	\ if expand("<afile>:e") == "m4"
2458	\|  call s:StarSetf('fvwm2m4')
2459	\|else
2460	\|  let b:fvwm_version = 2 | call s:StarSetf('fvwm')
2461	\|endif
2462
2463" Gedcom
2464au BufNewFile,BufRead */tmp/lltmp*		call s:StarSetf('gedcom')
2465
2466" GTK RC
2467au BufNewFile,BufRead .gtkrc*,gtkrc*		call s:StarSetf('gtkrc')
2468
2469" Jam
2470au BufNewFile,BufRead Prl*.*,JAM*.*		call s:StarSetf('jam')
2471
2472" Jargon
2473au! BufNewFile,BufRead *jarg*
2474	\ if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'THIS IS THE JARGON FILE'
2475	\|  call s:StarSetf('jargon')
2476	\|endif
2477
2478" Kconfig
2479au BufNewFile,BufRead Kconfig.*			call s:StarSetf('kconfig')
2480
2481" Lilo: Linux loader
2482au BufNewFile,BufRead lilo.conf*		call s:StarSetf('lilo')
2483
2484" Logcheck
2485au BufNewFile,BufRead */etc/logcheck/*.d*/*	call s:StarSetf('logcheck')
2486
2487" Makefile
2488au BufNewFile,BufRead [mM]akefile*		call s:StarSetf('make')
2489
2490" Ruby Makefile
2491au BufNewFile,BufRead [rR]akefile*		call s:StarSetf('ruby')
2492
2493" Mail (also matches muttrc.vim, so this is below the other checks)
2494au BufNewFile,BufRead mutt[[:alnum:]._-]\{6\}	setf mail
2495
2496" Modconf
2497au BufNewFile,BufRead */etc/modutils/*
2498	\ if executable(expand("<afile>")) != 1
2499	\|  call s:StarSetf('modconf')
2500	\|endif
2501au BufNewFile,BufRead */etc/modprobe.*		call s:StarSetf('modconf')
2502
2503" Mutt setup file
2504au BufNewFile,BufRead .mutt{ng,}rc*,*/.mutt{ng,}/mutt{ng,}rc*	call s:StarSetf('muttrc')
2505au BufNewFile,BufRead mutt{ng,}rc*,Mutt{ng,}rc*		call s:StarSetf('muttrc')
2506
2507" Nroff macros
2508au BufNewFile,BufRead tmac.*			call s:StarSetf('nroff')
2509
2510" Pam conf
2511au BufNewFile,BufRead */etc/pam.d/*		call s:StarSetf('pamconf')
2512
2513" Printcap and Termcap
2514au BufNewFile,BufRead *printcap*
2515	\ if !did_filetype()
2516	\|  let b:ptcap_type = "print" | call s:StarSetf('ptcap')
2517	\|endif
2518au BufNewFile,BufRead *termcap*
2519	\ if !did_filetype()
2520	\|  let b:ptcap_type = "term" | call s:StarSetf('ptcap')
2521	\|endif
2522
2523" Remind
2524au BufNewFile,BufRead .reminders*		call s:StarSetf('remind')
2525
2526" Vim script
2527au BufNewFile,BufRead *vimrc*			call s:StarSetf('vim')
2528
2529" Subversion commit file
2530au BufNewFile,BufRead svn-commit*.tmp		setf svn
2531
2532" X resources file
2533au BufNewFile,BufRead Xresources*,*/app-defaults/*,*/Xresources/* call s:StarSetf('xdefaults')
2534
2535" XFree86 config
2536au BufNewFile,BufRead XF86Config-4*
2537	\ let b:xf86conf_xfree86_version = 4 | call s:StarSetf('xf86conf')
2538au BufNewFile,BufRead XF86Config*
2539	\ if getline(1) =~ '\<XConfigurator\>'
2540	\|  let b:xf86conf_xfree86_version = 3
2541	\|endif
2542	\|call s:StarSetf('xf86conf')
2543
2544" X11 xmodmap
2545au BufNewFile,BufRead *xmodmap*			call s:StarSetf('xmodmap')
2546
2547" Xinetd conf
2548au BufNewFile,BufRead */etc/xinetd.d/*		call s:StarSetf('xinetd')
2549
2550" yum conf (close enough to dosini)
2551au BufNewFile,BufRead */etc/yum.repos.d/* 	call s:StarSetf('dosini')
2552
2553" Z-Shell script
2554au BufNewFile,BufRead zsh*,zlog*		call s:StarSetf('zsh')
2555
2556
2557" Plain text files, needs to be far down to not override others.  This avoids
2558" the "conf" type being used if there is a line starting with '#'.
2559au BufNewFile,BufRead *.txt,*.text		setf text
2560
2561
2562" Use the filetype detect plugins.  They may overrule any of the previously
2563" detected filetypes.
2564runtime! ftdetect/*.vim
2565
2566" NOTE: The above command could have ended the filetypedetect autocmd group
2567" and started another one. Let's make sure it has ended to get to a consistent
2568" state.
2569augroup END
2570
2571" Generic configuration file (check this last, it's just guessing!)
2572au filetypedetect BufNewFile,BufRead,StdinReadPost *
2573	\ if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat
2574	\    && (getline(1) =~ '^#' || getline(2) =~ '^#' || getline(3) =~ '^#'
2575	\	|| getline(4) =~ '^#' || getline(5) =~ '^#') |
2576	\   setf conf |
2577	\ endif
2578
2579
2580" If the GUI is already running, may still need to install the Syntax menu.
2581" Don't do it when the 'M' flag is included in 'guioptions'.
2582if has("menu") && has("gui_running")
2583      \ && !exists("did_install_syntax_menu") && &guioptions !~# "M"
2584  source <sfile>:p:h/menu.vim
2585endif
2586
2587" Function called for testing all functions defined here.  These are
2588" script-local, thus need to be executed here.
2589" Returns a string with error messages (hopefully empty).
2590func! TestFiletypeFuncs(testlist)
2591  let output = ''
2592  for f in a:testlist
2593    try
2594      exe f
2595    catch
2596      let output = output . "\n" . f . ": " . v:exception
2597    endtry
2598  endfor
2599  return output
2600endfunc
2601
2602" Restore 'cpoptions'
2603let &cpo = s:cpo_save
2604unlet s:cpo_save
2605