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