Add support for a global "Plug-In" menu
[MacVim.git] / runtime / filetype.vim
blob89af04cce508bb259ba0ab3a8a482f5c2f2c8429
1 " Vim support file to detect file types
3 " Maintainer:   Bram Moolenaar <Bram@vim.org>
4 " Last Change:  2008 Jun 20
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,?\+.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 " . 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   if head =~ '\sasmsyntax=\S\+\s'
193     let b:asmsyntax = substitute(head, '.*\sasmsyntax=\([a-zA-Z0-9]\+\)\s.*','\1', "")
194   elseif ((head =~? '\.title') || (head =~? '\.ident') || (head =~? '\.macro') || (head =~? '\.subtitle') || (head =~? '\.library'))
195     let b:asmsyntax = "vmasm"
196   endif
197 endfunc
199 " Macro (VAX)
200 au BufNewFile,BufRead *.mar                     setf vmasm
202 " Atlas
203 au BufNewFile,BufRead *.atl,*.as                setf atlas
205 " Autoit v3
206 au BufNewFile,BufRead *.au3                     setf autoit
208 " Autohotkey
209 au BufNewFile,BufRead *.ahk                     setf autohotkey
211 " Automake
212 au BufNewFile,BufRead [mM]akefile.am,GNUmakefile.am     setf automake
214 " Autotest .at files are actually m4
215 au BufNewFile,BufRead *.at                      setf m4
217 " Avenue
218 au BufNewFile,BufRead *.ave                     setf ave
220 " Awk
221 au BufNewFile,BufRead *.awk                     setf awk
223 " B
224 au BufNewFile,BufRead *.mch,*.ref,*.imp         setf b
226 " BASIC or Visual Basic
227 au BufNewFile,BufRead *.bas                     call s:FTVB("basic")
229 " Check if one of the first five lines contains "VB_Name".  In that case it is
230 " probably a Visual Basic file.  Otherwise it's assumed to be "alt" filetype.
231 func! s:FTVB(alt)
232   if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'VB_Name\|Begin VB\.\(Form\|MDIForm\|UserControl\)'
233     setf vb
234   else
235     exe "setf " . a:alt
236   endif
237 endfunc
239 " Visual Basic Script (close to Visual Basic)
240 au BufNewFile,BufRead *.vbs,*.dsm,*.ctl         setf vb
242 " IBasic file (similar to QBasic)
243 au BufNewFile,BufRead *.iba,*.ibi               setf ibasic
245 " FreeBasic file (similar to QBasic)
246 au BufNewFile,BufRead *.fb,*.bi                 setf freebasic
248 " Batch file for MSDOS.
249 au BufNewFile,BufRead *.bat,*.sys               setf dosbatch
250 " *.cmd is close to a Batch file, but on OS/2 Rexx files also use *.cmd.
251 au BufNewFile,BufRead *.cmd
252         \ if getline(1) =~ '^/\*' | setf rexx | else | setf dosbatch | endif
254 " Batch file for 4DOS
255 au BufNewFile,BufRead *.btm                     call s:FTbtm()
256 func! s:FTbtm()
257   if exists("g:dosbatch_syntax_for_btm") && g:dosbatch_syntax_for_btm
258     setf dosbatch
259   else
260     setf btm
261   endif
262 endfunc
264 " BC calculator
265 au BufNewFile,BufRead *.bc                      setf bc
267 " BDF font
268 au BufNewFile,BufRead *.bdf                     setf bdf
270 " BibTeX bibliography database file
271 au BufNewFile,BufRead *.bib                     setf bib
273 " BibTeX Bibliography Style
274 au BufNewFile,BufRead *.bst                     setf bst
276 " BIND configuration
277 au BufNewFile,BufRead named.conf,rndc.conf      setf named
279 " BIND zone
280 au BufNewFile,BufRead named.root                setf bindzone
281 au BufNewFile,BufRead *.db                      call s:BindzoneCheck('')
283 func! s:BindzoneCheck(default)
284   if getline(1).getline(2).getline(3).getline(4) =~ '^; <<>> DiG [0-9.]\+ <<>>\|BIND.*named\|$ORIGIN\|$TTL\|IN\s\+SOA'
285     setf bindzone
286   elseif a:default != ''
287     exe 'setf ' . a:default
288   endif
289 endfunc
291 " Blank
292 au BufNewFile,BufRead *.bl                      setf blank
294 " C or lpc
295 au BufNewFile,BufRead *.c                       call s:FTlpc()
297 func! s:FTlpc()
298   if exists("g:lpc_syntax_for_c")
299     let lnum = 1
300     while lnum <= 12
301       if getline(lnum) =~# '^\(//\|inherit\|private\|protected\|nosave\|string\|object\|mapping\|mixed\)'
302         setf lpc
303         return
304       endif
305       let lnum = lnum + 1
306     endwhile
307   endif
308   setf c
309 endfunc
311 " Calendar
312 au BufNewFile,BufRead calendar                  setf calendar
313 au BufNewFile,BufRead */.calendar/*,
314         \*/share/calendar/*/calendar.*,*/share/calendar/calendar.*
315         \                                       call s:StarSetf('calendar')
317 " C#
318 au BufNewFile,BufRead *.cs                      setf cs
320 " Cdrdao TOC
321 au BufNewFile,BufRead *.toc                     setf cdrtoc
323 " Cdrdao config
324 au BufNewFile,BufRead etc/cdrdao.conf,etc/defaults/cdrdao,etc/default/cdrdao,~/.cdrdao                                          setf cdrdaoconf
326 " Cfengine
327 au BufNewFile,BufRead cfengine.conf             setf cfengine
329 " Comshare Dimension Definition Language
330 au BufNewFile,BufRead *.cdl                     setf cdl
332 " Conary Recipe
333 au BufNewFile,BufRead *.recipe                  setf conaryrecipe
335 " Controllable Regex Mutilator
336 au BufNewFile,BufRead *.crm                     setf crm
338 " Cyn++
339 au BufNewFile,BufRead *.cyn                     setf cynpp
341 " Cynlib
342 " .cc and .cpp files can be C++ or Cynlib.
343 au BufNewFile,BufRead *.cc
344         \ if exists("cynlib_syntax_for_cc")|setf cynlib|else|setf cpp|endif
345 au BufNewFile,BufRead *.cpp
346         \ if exists("cynlib_syntax_for_cpp")|setf cynlib|else|setf cpp|endif
348 " C++
349 if has("fname_case")
350   au BufNewFile,BufRead *.cxx,*.c++,*.C,*.H,*.hh,*.hxx,*.hpp,*.moc,*.tcc,*.inl setf cpp
351 else
352   au BufNewFile,BufRead *.cxx,*.c++,*.hh,*.hxx,*.hpp,*.moc,*.tcc,*.inl setf cpp
353 endif
355 " .h files can be C, Ch C++, ObjC or ObjC++.
356 " Set c_syntax_for_h if you want C, ch_syntax_for_h if you want Ch. ObjC is
357 " detected automatically.
358 au BufNewFile,BufRead *.h                       call s:FTheader()
360 func! s:FTheader()
361   if match(getline(1, min([line("$"), 200])), '^@\(interface\|end\|class\)') > -1
362     setf objc
363   elseif exists("c_syntax_for_h")
364     setf c
365   elseif exists("ch_syntax_for_h")
366     setf ch
367   else
368     setf cpp
369   endif
370 endfunc
372 " Ch (CHscript)
373 au BufNewFile,BufRead *.chf                     setf ch
375 " TLH files are C++ headers generated by Visual C++'s #import from typelibs
376 au BufNewFile,BufRead *.tlh                     setf cpp
378 " Cascading Style Sheets
379 au BufNewFile,BufRead *.css                     setf css
381 " Century Term Command Scripts (*.cmd too)
382 au BufNewFile,BufRead *.con                     setf cterm
384 " Changelog
385 au BufNewFile,BufRead changelog.Debian,changelog.dch,NEWS.Debian,NEWS.dch
386                                         \       setf debchangelog
388 au BufNewFile,BufRead [cC]hange[lL]og
389         \  if getline(1) =~ '; urgency='
390         \|   setf debchangelog
391         \| else
392         \|   setf changelog
393         \| endif
395 au BufNewFile,BufRead NEWS
396         \  if getline(1) =~ '; urgency='
397         \|   setf debchangelog
398         \| endif
400 " CHILL
401 au BufNewFile,BufRead *..ch                     setf chill
403 " Changes for WEB and CWEB or CHILL
404 au BufNewFile,BufRead *.ch                      call s:FTchange()
406 " This function checks if one of the first ten lines start with a '@'.  In
407 " that case it is probably a change file.
408 " If the first line starts with # or ! it's probably a ch file.
409 " If a line has "main", "include", "//" ir "/*" it's probably ch.
410 " Otherwise CHILL is assumed.
411 func! s:FTchange()
412   let lnum = 1
413   while lnum <= 10
414     if getline(lnum)[0] == '@'
415       setf change
416       return
417     endif
418     if lnum == 1 && (getline(1)[0] == '#' || getline(1)[0] == '!')
419       setf ch
420       return
421     endif
422     if getline(lnum) =~ "MODULE"
423       setf chill
424       return
425     endif
426     if getline(lnum) =~ 'main\s*(\|#\s*include\|//'
427       setf ch
428       return
429     endif
430     let lnum = lnum + 1
431   endwhile
432   setf chill
433 endfunc
435 " ChordPro
436 au BufNewFile,BufRead *.chopro,*.crd,*.cho,*.crdpro,*.chordpro  setf chordpro
438 " Clean
439 au BufNewFile,BufRead *.dcl,*.icl               setf clean
441 " Clever
442 au BufNewFile,BufRead *.eni                     setf cl
444 " Clever or dtd
445 au BufNewFile,BufRead *.ent                     call s:FTent()
447 func! s:FTent()
448   " This function checks for valid cl syntax in the first five lines.
449   " Look for either an opening comment, '#', or a block start, '{".
450   " If not found, assume SGML.
451   let lnum = 1
452   while lnum < 6
453     let line = getline(lnum)
454     if line =~ '^\s*[#{]'
455       setf cl
456       return
457     elseif line !~ '^\s*$'
458       " Not a blank line, not a comment, and not a block start,
459       " so doesn't look like valid cl code.
460       break
461     endif
462     let lnum = lnum + 1
463   endw
464   setf dtd
465 endfunc
467 " Clipper (or FoxPro; could also be eviews)
468 au BufNewFile,BufRead *.prg
469         \ if exists("g:filetype_prg") |
470         \   exe "setf " . g:filetype_prg |
471         \ else |
472         \   setf clipper |
473         \ endif
475 " Cmake
476 au BufNewFile,BufRead CMakeLists.txt,*.cmake,*.cmake.in         setf cmake
478 " Cmusrc
479 au BufNewFile,BufRead ~/.cmus/{autosave,rc,command-history,*.theme} setf cmusrc
480 au BufNewFile,BufRead */cmus/{rc,*.theme}                       setf cmusrc
482 " Cobol
483 au BufNewFile,BufRead *.cbl,*.cob,*.lib setf cobol
484 "   cobol or zope form controller python script? (heuristic)
485 au BufNewFile,BufRead *.cpy
486         \ if getline(1) =~ '^##' |
487         \   setf python |
488         \ else |
489         \   setf cobol |
490         \ endif
492 " Coco/R
493 au BufNewFile,BufRead *.atg                     setf coco
495 " Cold Fusion
496 au BufNewFile,BufRead *.cfm,*.cfi,*.cfc         setf cf
498 " Configure scripts
499 au BufNewFile,BufRead configure.in,configure.ac setf config
501 " CUDA  Cumpute Unified Device Architecture
502 au BufNewFile,BufRead *.cu                      setf cuda
504 " WildPackets EtherPeek Decoder
505 au BufNewFile,BufRead *.dcd                     setf dcd
507 " Enlightenment configuration files
508 au BufNewFile,BufRead *enlightenment/*.cfg      setf c
510 " Eterm
511 au BufNewFile,BufRead *Eterm/*.cfg              setf eterm
513 " Lynx config files
514 au BufNewFile,BufRead lynx.cfg                  setf lynx
516 " Quake
517 au BufNewFile,BufRead *baseq[2-3]/*.cfg,*id1/*.cfg      setf quake
518 au BufNewFile,BufRead *quake[1-3]/*.cfg                 setf quake
520 " Quake C
521 au BufNewFile,BufRead *.qc                      setf c
523 " Configure files
524 au BufNewFile,BufRead *.cfg                     setf cfg
526 " Communicating Sequential Processes
527 au BufNewFile,BufRead *.csp,*.fdr               setf csp
529 " CUPL logic description and simulation
530 au BufNewFile,BufRead *.pld                     setf cupl
531 au BufNewFile,BufRead *.si                      setf cuplsim
533 " Debian Control
534 au BufNewFile,BufRead */debian/control          setf debcontrol
535 au BufNewFile,BufRead control
536         \  if getline(1) =~ '^Source:'
537         \|   setf debcontrol
538         \| endif
540 " Debian Sources.list
541 au BufNewFile,BufRead /etc/apt/sources.list     setf debsources
543 " Deny hosts
544 au BufNewFile,BufRead denyhosts.conf            setf denyhosts
546 " ROCKLinux package description
547 au BufNewFile,BufRead *.desc                    setf desc
549 " the D language or dtrace
550 au BufNewFile,BufRead *.d                       call s:DtraceCheck()
552 func! s:DtraceCheck()
553   let lines = getline(1, min([line("$"), 100]))
554   if match(lines, '^#!\S\+dtrace\|#pragma\s\+D\s\+option\|:\S\{-}:\S\{-}:') > -1
555     setf dtrace
556   else
557     setf d
558   endif
559 endfunc
561 " Desktop files
562 au BufNewFile,BufRead *.desktop,.directory      setf desktop
564 " Dict config
565 au BufNewFile,BufRead dict.conf,.dictrc         setf dictconf
567 " Dictd config
568 au BufNewFile,BufRead dictd.conf                setf dictdconf
570 " Diff files
571 au BufNewFile,BufRead *.diff,*.rej,*.patch      setf diff
573 " Dircolors
574 au BufNewFile,BufRead .dir_colors,/etc/DIR_COLORS       setf dircolors
576 " Diva (with Skill) or InstallShield
577 au BufNewFile,BufRead *.rul
578         \ if getline(1).getline(2).getline(3).getline(4).getline(5).getline(6) =~? 'InstallShield' |
579         \   setf ishd |
580         \ else |
581         \   setf diva |
582         \ endif
584 " DCL (Digital Command Language - vms) or DNS zone file
585 au BufNewFile,BufRead *.com                     call s:BindzoneCheck('dcl')
587 " DOT
588 au BufNewFile,BufRead *.dot                     setf dot
590 " Dylan - lid files
591 au BufNewFile,BufRead *.lid                     setf dylanlid
593 " Dylan - intr files (melange)
594 au BufNewFile,BufRead *.intr                    setf dylanintr
596 " Dylan
597 au BufNewFile,BufRead *.dylan                   setf dylan
599 " Microsoft Module Definition
600 au BufNewFile,BufRead *.def                     setf def
602 " Dracula
603 au BufNewFile,BufRead *.drac,*.drc,*lvs,*lpe    setf dracula
605 " dsl
606 au BufNewFile,BufRead *.dsl                     setf dsl
608 " DTD (Document Type Definition for XML)
609 au BufNewFile,BufRead *.dtd                     setf dtd
611 " EDIF (*.edf,*.edif,*.edn,*.edo)
612 au BufNewFile,BufRead *.ed\(f\|if\|n\|o\)       setf edif
614 " Embedix Component Description
615 au BufNewFile,BufRead *.ecd                     setf ecd
617 " Eiffel or Specman
618 au BufNewFile,BufRead *.e,*.E                   call s:FTe()
620 " Elinks configuration
621 au BufNewFile,BufRead */etc/elinks.conf,*/.elinks/elinks.conf   setf elinks
623 func! s:FTe()
624   let n = 1
625   while n < 100 && n < line("$")
626     if getline(n) =~ "^\\s*\\(<'\\|'>\\)\\s*$"
627       setf specman
628       return
629     endif
630     let n = n + 1
631   endwhile
632   setf eiffel
633 endfunc
635 " ERicsson LANGuage; Yaws is erlang too
636 au BufNewFile,BufRead *.erl,*.yaws              setf erlang
638 " Elm Filter Rules file
639 au BufNewFile,BufRead filter-rules              setf elmfilt
641 " ESMTP rc file
642 au BufNewFile,BufRead *esmtprc                  setf esmtprc
644 " ESQL-C
645 au BufNewFile,BufRead *.ec,*.EC                 setf esqlc
647 " Esterel
648 au BufNewFile,BufRead *.strl                    setf esterel
650 " Essbase script
651 au BufNewFile,BufRead *.csc                     setf csc
653 " Exim
654 au BufNewFile,BufRead exim.conf                 setf exim
656 " Expect
657 au BufNewFile,BufRead *.exp                     setf expect
659 " Exports
660 au BufNewFile,BufRead exports                   setf exports
662 " Factor
663 au BufNewFile,BufRead *.factor                  setf factor
665 " Fetchmail RC file
666 au BufNewFile,BufRead .fetchmailrc              setf fetchmail
668 " FlexWiki
669 au BufNewFile,BufRead *.wiki                    setf flexwiki
671 " Focus Executable
672 au BufNewFile,BufRead *.fex,*.focexec           setf focexec
674 " Focus Master file (but not for auto.master)
675 au BufNewFile,BufRead auto.master               setf conf
676 au BufNewFile,BufRead *.mas,*.master            setf master
678 " Forth
679 au BufNewFile,BufRead *.fs,*.ft                 setf forth
681 " Reva Forth
682 au BufNewFile,BufRead *.frt                     setf reva
684 " Fortran
685 if has("fname_case")
686   au BufNewFile,BufRead *.F,*.FOR,*.FPP,*.FTN,*.F77,*.F90,*.F95  setf fortran
687 endif
688 au BufNewFile,BufRead   *.f,*.for,*.fortran,*.fpp,*.ftn,*.f77,*.f90,*.f95  setf fortran
690 " FStab
691 au BufNewFile,BufRead fstab,mtab                setf fstab
693 " GDB command files
694 au BufNewFile,BufRead .gdbinit                  setf gdb
696 " GDMO
697 au BufNewFile,BufRead *.mo,*.gdmo               setf gdmo
699 " Gedcom
700 au BufNewFile,BufRead *.ged                     setf gedcom
702 " Git
703 autocmd BufNewFile,BufRead *.git/COMMIT_EDITMSG    setf gitcommit
704 autocmd BufNewFile,BufRead *.git/config,.gitconfig setf gitconfig
705 autocmd BufNewFile,BufRead git-rebase-todo         setf gitrebase
706 autocmd BufNewFile,BufRead .msg.[0-9]*
707       \ if getline(1) =~ '^From.*# This line is ignored.$' |
708       \   setf gitsendemail |
709       \ endif
710 autocmd BufNewFile,BufRead *.git/**
711       \ if getline(1) =~ '^\x\{40\}\>\|^ref: ' |
712       \   setf git |
713       \ endif
715 " Gkrellmrc
716 au BufNewFile,BufRead gkrellmrc,gkrellmrc_?     setf gkrellmrc
718 " GP scripts (2.0 and onward)
719 au BufNewFile,BufRead *.gp,.gprc                setf gp
721 " GPG
722 au BufNewFile,BufRead */.gnupg/options          setf gpg
723 au BufNewFile,BufRead */.gnupg/gpg.conf         setf gpg
724 au BufNewFile,BufRead /usr/**/gnupg/options.skel setf gpg
726 " Gnuplot scripts
727 au BufNewFile,BufRead *.gpi                     setf gnuplot
729 " GrADS scripts
730 au BufNewFile,BufRead *.gs                      setf grads
732 " Gretl
733 au BufNewFile,BufRead *.gretl                   setf gretl
735 " Groovy
736 au BufNewFile,BufRead *.groovy                  setf groovy
738 " GNU Server Pages
739 au BufNewFile,BufRead *.gsp                     setf gsp
741 " Group file
742 au BufNewFile,BufRead /etc/group                setf group
744 " GTK RC
745 au BufNewFile,BufRead .gtkrc,gtkrc              setf gtkrc
747 " Hamster Classic | Playground files
748 au BufNewFile,BufRead *.hsc,*.hsm               setf hamster
750 " Haskell
751 au BufNewFile,BufRead *.hs                      setf haskell
752 au BufNewFile,BufRead *.lhs                     setf lhaskell
753 au BufNewFile,BufRead *.chs                     setf chaskell
755 " Haste
756 au BufNewFile,BufRead *.ht                      setf haste
758 " Hercules
759 au BufNewFile,BufRead *.vc,*.ev,*.rs,*.sum,*.errsum     setf hercules
761 " HEX (Intel)
762 au BufNewFile,BufRead *.hex,*.h32               setf hex
764 " Tilde (must be before HTML)
765 au BufNewFile,BufRead *.t.html                  setf tilde
767 " HTML (.shtml and .stm for server side)
768 au BufNewFile,BufRead *.html,*.htm,*.shtml,*.stm  call s:FThtml()
770 " Distinguish between HTML, XHTML and Django
771 func! s:FThtml()
772   let n = 1
773   while n < 10 && n < line("$")
774     if getline(n) =~ '\<DTD\s\+XHTML\s'
775       setf xhtml
776       return
777     endif
778     if getline(n) =~ '{%\s*\(extends\|block\)\>'
779       setf htmldjango
780       return
781     endif
782     let n = n + 1
783   endwhile
784   setf html
785 endfunc
787 " HTML with Ruby - eRuby
788 au BufNewFile,BufRead *.erb,*.rhtml             setf eruby
790 " HTML with M4
791 au BufNewFile,BufRead *.html.m4                 setf htmlm4
793 " HTML Cheetah template
794 au BufNewFile,BufRead *.tmpl                    setf htmlcheetah
796 " Host config
797 au BufNewFile,BufRead /etc/host.conf            setf hostconf
799 " Hyper Builder
800 au BufNewFile,BufRead *.hb                      setf hb
802 " Icon
803 au BufNewFile,BufRead *.icn                     setf icon
805 " IDL (Interface Description Language)
806 au BufNewFile,BufRead *.idl                     call s:FTidl()
808 " Distinguish between standard IDL and MS-IDL
809 func! s:FTidl()
810   let n = 1
811   while n < 50 && n < line("$")
812     if getline(n) =~ '^\s*import\s\+"\(unknwn\|objidl\)\.idl"'
813       setf msidl
814       return
815     endif
816     let n = n + 1
817   endwhile
818   setf idl
819 endfunc
821 " Microsoft IDL (Interface Description Language)  Also *.idl
822 " MOF = WMI (Windows Management Instrumentation) Managed Object Format
823 au BufNewFile,BufRead *.odl,*.mof               setf msidl
825 " Icewm menu
826 au BufNewFile,BufRead */.icewm/menu             setf icemenu
828 " Indent profile (must come before IDL *.pro!)
829 au BufNewFile,BufRead .indent.pro               setf indent
830 au BufNewFile,BufRead indent.pro                call s:ProtoCheck('indent')
832 " IDL (Interactive Data Language)
833 au BufNewFile,BufRead *.pro                     call s:ProtoCheck('idlang')
835 " Distinguish between "default" and Cproto prototype file. */
836 func! s:ProtoCheck(default)
837   " Cproto files have a comment in the first line and a function prototype in
838   " the second line, it always ends in ";".  Indent files may also have
839   " comments, thus we can't match comments to see the difference.
840   if getline(2) =~ ';$'
841     setf cpp
842   else
843     exe 'setf ' . a:default
844   endif
845 endfunc
848 " Indent RC
849 au BufNewFile,BufRead indentrc                  setf indentrc
851 " Inform
852 au BufNewFile,BufRead *.inf,*.INF               setf inform
854 " Initng
855 au BufNewFile,BufRead /etc/initng/**/*.i,*.ii   setf initng
857 " Ipfilter
858 au BufNewFile,BufRead ipf.conf,ipf6.conf,ipf.rules      setf ipfilter
860 " Informix 4GL (source - canonical, include file, I4GL+M4 preproc.)
861 au BufNewFile,BufRead *.4gl,*.4gh,*.m4gl        setf fgl
863 " .INI file for MSDOS
864 au BufNewFile,BufRead *.ini                     setf dosini
866 " SysV Inittab
867 au BufNewFile,BufRead inittab                   setf inittab
869 " Inno Setup
870 au BufNewFile,BufRead *.iss                     setf iss
872 " JAL
873 au BufNewFile,BufRead *.jal,*.JAL               setf jal
875 " Jam
876 au BufNewFile,BufRead *.jpl,*.jpr               setf jam
878 " Java
879 au BufNewFile,BufRead *.java,*.jav              setf java
881 " JavaCC
882 au BufNewFile,BufRead *.jj,*.jjt                setf javacc
884 " JavaScript, ECMAScript
885 au BufNewFile,BufRead *.js,*.javascript,*.es    setf javascript
887 " Java Server Pages
888 au BufNewFile,BufRead *.jsp                     setf jsp
890 " Java Properties resource file (note: doesn't catch font.properties.pl)
891 au BufNewFile,BufRead *.properties,*.properties_??,*.properties_??_??   setf jproperties
892 au BufNewFile,BufRead *.properties_??_??_*      call s:StarSetf('jproperties')
894 " Jess
895 au BufNewFile,BufRead *.clp                     setf jess
897 " Jgraph
898 au BufNewFile,BufRead *.jgr                     setf jgraph
900 " Kixtart
901 au BufNewFile,BufRead *.kix                     setf kix
903 " Kimwitu[++]
904 au BufNewFile,BufRead *.k                       setf kwt
906 " KDE script
907 au BufNewFile,BufRead *.ks                      setf kscript
909 " Kconfig
910 au BufNewFile,BufRead Kconfig,Kconfig.debug     setf kconfig
912 " Lace (ISE)
913 au BufNewFile,BufRead *.ace,*.ACE               setf lace
915 " Latte
916 au BufNewFile,BufRead *.latte,*.lte             setf latte
918 " Limits
919 au BufNewFile,BufRead /etc/limits               setf limits
921 " LambdaProlog (*.mod too, see Modsim)
922 au BufNewFile,BufRead *.sig                     setf lprolog
924 " LDAP LDIF
925 au BufNewFile,BufRead *.ldif                    setf ldif
927 " Ld loader
928 au BufNewFile,BufRead *.ld                      setf ld
930 " Lex
931 au BufNewFile,BufRead *.lex,*.l                 setf lex
933 " Libao
934 au BufNewFile,BufRead /etc/libao.conf,*/.libao  setf libao
936 " Libsensors
937 au BufNewFile,BufRead /etc/sensors.conf         setf sensors
939 " LFTP
940 au BufNewFile,BufRead lftp.conf,.lftprc,*lftp/rc        setf lftp
942 " Lifelines (or Lex for C++!)
943 au BufNewFile,BufRead *.ll                      setf lifelines
945 " Lilo: Linux loader
946 au BufNewFile,BufRead lilo.conf*                call s:StarSetf('lilo')
948 " Lisp (*.el = ELisp, *.cl = Common Lisp, *.jl = librep Lisp)
949 if has("fname_case")
950   au BufNewFile,BufRead *.lsp,*.lisp,*.el,*.cl,*.jl,*.L,.emacs,.sawfishrc setf lisp
951 else
952   au BufNewFile,BufRead *.lsp,*.lisp,*.el,*.cl,*.jl,.emacs,.sawfishrc setf lisp
953 endif
955 " SBCL implementation of Common Lisp
956 au BufNewFile,BufRead sbclrc,.sbclrc            setf lisp
958 " Lite
959 au BufNewFile,BufRead *.lite,*.lt               setf lite
961 " LiteStep RC files
962 au BufNewFile,BufRead */LiteStep/*/*.rc         setf litestep
964 " Login access
965 au BufNewFile,BufRead /etc/login.access         setf loginaccess
967 " Login defs
968 au BufNewFile,BufRead /etc/login.defs           setf logindefs
970 " Logtalk
971 au BufNewFile,BufRead *.lgt                     setf logtalk
973 " LOTOS
974 au BufNewFile,BufRead *.lot,*.lotos             setf lotos
976 " Lout (also: *.lt)
977 au BufNewFile,BufRead *.lou,*.lout              setf lout
979 " Lua
980 au BufNewFile,BufRead *.lua                     setf lua
982 " Linden Scripting Language (Second Life)
983 au BufNewFile,BufRead *.lsl                     setf lsl
985 " Lynx style file (or LotusScript!)
986 au BufNewFile,BufRead *.lss                     setf lss
988 " M4
989 au BufNewFile,BufRead *.m4
990         \ if expand("<afile>") !~? 'html.m4$\|fvwm2rc' | setf m4 | endif
992 " MaGic Point
993 au BufNewFile,BufRead *.mgp                     setf mgp
995 " Mail (for Elm, trn, mutt, muttng, rn, slrn)
996 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
998 " Mail aliases
999 au BufNewFile,BufRead /etc/mail/aliases,/etc/aliases    setf mailaliases
1001 " Mailcap configuration file
1002 au BufNewFile,BufRead .mailcap,mailcap          setf mailcap
1004 " Makefile
1005 au BufNewFile,BufRead *[mM]akefile,*.mk,*.mak,*.dsp setf make
1007 " MakeIndex
1008 au BufNewFile,BufRead *.ist,*.mst               setf ist
1010 " Manpage
1011 au BufNewFile,BufRead *.man                     setf man
1013 " Man config
1014 au BufNewFile,BufRead /etc/man.conf,man.config  setf manconf
1016 " Maple V
1017 au BufNewFile,BufRead *.mv,*.mpl,*.mws          setf maple
1019 " Mason
1020 au BufNewFile,BufRead *.mason,*.mhtml           setf mason
1022 " Matlab or Objective C
1023 au BufNewFile,BufRead *.m                       call s:FTm()
1025 func! s:FTm()
1026   let n = 1
1027   while n < 10
1028     let line = getline(n)
1029     if line =~ '^\s*\(#\s*\(include\|import\)\>\|/\*\)'
1030       setf objc
1031       return
1032     endif
1033     if line =~ '^\s*%'
1034       setf matlab
1035       return
1036     endif
1037     if line =~ '^\s*(\*'
1038       setf mma
1039       return
1040     endif
1041     let n = n + 1
1042   endwhile
1043   if exists("g:filetype_m")
1044     exe "setf " . g:filetype_m
1045   else
1046     setf matlab
1047   endif
1048 endfunc
1050 " Mathematica notebook
1051 au BufNewFile,BufRead *.nb                      setf mma
1053 " Maya Extension Language
1054 au BufNewFile,BufRead *.mel                     setf mel
1056 " Messages
1057 au BufNewFile,BufRead /var/log/messages,/var/log/messages.*[0-9]  setf messages
1059 " Metafont
1060 au BufNewFile,BufRead *.mf                      setf mf
1062 " MetaPost
1063 au BufNewFile,BufRead *.mp                      setf mp
1065 " MGL
1066 au BufNewFile,BufRead *.mgl                     setf mgl
1068 " MMIX or VMS makefile
1069 au BufNewFile,BufRead *.mms                     call s:FTmms()
1071 " Symbian meta-makefile definition (MMP)
1072 au BufNewFile,BufRead *.mmp                     setf mmp
1074 func! s:FTmms()
1075   let n = 1
1076   while n < 10
1077     let line = getline(n)
1078     if line =~ '^\s*\(%\|//\)' || line =~ '^\*'
1079       setf mmix
1080       return
1081     endif
1082     if line =~ '^\s*#'
1083       setf make
1084       return
1085     endif
1086     let n = n + 1
1087   endwhile
1088   setf mmix
1089 endfunc
1092 " Modsim III (or LambdaProlog)
1093 au BufNewFile,BufRead *.mod
1094         \ if getline(1) =~ '\<module\>' |
1095         \   setf lprolog |
1096         \ else |
1097         \   setf modsim3 |
1098         \ endif
1100 " Modula 2
1101 au BufNewFile,BufRead *.m2,*.DEF,*.MOD,*.md,*.mi setf modula2
1103 " Modula 3 (.m3, .i3, .mg, .ig)
1104 au BufNewFile,BufRead *.[mi][3g]                setf modula3
1106 " Monk
1107 au BufNewFile,BufRead *.isc,*.monk,*.ssc,*.tsc  setf monk
1109 " MOO
1110 au BufNewFile,BufRead *.moo                     setf moo
1112 " Modconf
1113 au BufNewFile,BufRead /etc/modules.conf,/etc/conf.modules       setf modconf
1114 au BufNewFile,BufRead /etc/modutils/*
1115         \ if executable(expand("<afile>")) != 1
1116         \|  call s:StarSetf('modconf')
1117         \|endif
1119 " Mplayer config
1120 au BufNewFile,BufRead mplayer.conf,*/.mplayer/config    setf mplayerconf
1122 " Moterola S record
1123 au BufNewFile,BufRead *.s19,*.s28,*.s37         setf srec
1125 " Mrxvtrc
1126 au BufNewFile,BufRead mrxvtrc,.mrxvtrc          setf mrxvtrc
1128 " Msql
1129 au BufNewFile,BufRead *.msql                    setf msql
1131 " Mysql
1132 au BufNewFile,BufRead *.mysql                   setf mysql
1134 " M$ Resource files
1135 au BufNewFile,BufRead *.rc                      setf rc
1137 " MuPAD source
1138 au BufRead,BufNewFile *.mu                      setf mupad
1140 " Mush
1141 au BufNewFile,BufRead *.mush                    setf mush
1143 " Mutt setup file (also for Muttng)
1144 au BufNewFile,BufRead Mutt{ng,}rc               setf muttrc
1146 " Nano
1147 au BufNewFile,BufRead /etc/nanorc,.nanorc       setf nanorc
1149 " Nastran input/DMAP
1150 "au BufNewFile,BufRead *.dat                    setf nastran
1152 " Natural
1153 au BufNewFile,BufRead *.NS[ACGLMNPS]            setf natural
1155 " Netrc
1156 au BufNewFile,BufRead .netrc                    setf netrc
1158 " Novell netware batch files
1159 au BufNewFile,BufRead *.ncf                     setf ncf
1161 " Nroff/Troff (*.ms and *.t are checked below)
1162 au BufNewFile,BufRead *.me
1163         \ if expand("<afile>") != "read.me" && expand("<afile>") != "click.me" |
1164         \   setf nroff |
1165         \ endif
1166 au BufNewFile,BufRead *.tr,*.nr,*.roff,*.tmac,*.mom     setf nroff
1167 au BufNewFile,BufRead *.[1-9]                   call s:FTnroff()
1169 " This function checks if one of the first five lines start with a dot.  In
1170 " that case it is probably an nroff file: 'filetype' is set and 1 is returned.
1171 func! s:FTnroff()
1172   if getline(1)[0] . getline(2)[0] . getline(3)[0] . getline(4)[0] . getline(5)[0] =~ '\.'
1173     setf nroff
1174     return 1
1175   endif
1176   return 0
1177 endfunc
1179 " Nroff or Objective C++
1180 au BufNewFile,BufRead *.mm                      call s:FTmm()
1182 func! s:FTmm()
1183   let n = 1
1184   while n < 10
1185     let line = getline(n)
1186     if line =~ '^\s*\(#\s*\(include\|import\)\>\|/\*\)'
1187       setf objcpp
1188       return
1189     endif
1190     let n = n + 1
1191   endwhile
1192   setf nroff
1193 endfunc
1195 " Not Quite C
1196 au BufNewFile,BufRead *.nqc                     setf nqc
1198 " NSIS
1199 au BufNewFile,BufRead *.nsi                     setf nsis
1201 " OCAML
1202 au BufNewFile,BufRead *.ml,*.mli,*.mll,*.mly    setf ocaml
1204 " Occam
1205 au BufNewFile,BufRead *.occ                     setf occam
1207 " Omnimark
1208 au BufNewFile,BufRead *.xom,*.xin               setf omnimark
1210 " OpenROAD
1211 au BufNewFile,BufRead *.or                      setf openroad
1213 " OPL
1214 au BufNewFile,BufRead *.[Oo][Pp][Ll]            setf opl
1216 " Oracle config file
1217 au BufNewFile,BufRead *.ora                     setf ora
1219 " Packet filter conf
1220 au BufNewFile,BufRead pf.conf                   setf pf
1222 " Pam conf
1223 au BufNewFile,BufRead /etc/pam.conf             setf pamconf
1225 " PApp
1226 au BufNewFile,BufRead *.papp,*.pxml,*.pxsl      setf papp
1228 " Password file
1229 au BufNewFile,BufRead /etc/passwd,/etc/shadow,/etc/shadow- setf passwd
1231 " Pascal (also *.p)
1232 au BufNewFile,BufRead *.pas                     setf pascal
1234 " Delphi project file
1235 au BufNewFile,BufRead *.dpr                     setf pascal
1237 " PDF
1238 au BufNewFile,BufRead *.pdf                     setf pdf
1240 " Perl
1241 if has("fname_case")
1242   au BufNewFile,BufRead *.pl,*.PL               call s:FTpl()
1243 else
1244   au BufNewFile,BufRead *.pl                    call s:FTpl()
1245 endif
1246 au BufNewFile,BufRead *.plx                     setf perl
1248 func! s:FTpl()
1249   if exists("g:filetype_pl")
1250     exe "setf " . g:filetype_pl
1251   else
1252     " recognize Prolog by specific text in the first non-empty line
1253     " require a blank after the '%' because Perl uses "%list" and "%translate"
1254     let l = getline(nextnonblank(1))
1255     if l =~ '\<prolog\>' || l =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || l =~ ':-'
1256       setf prolog
1257     else
1258       setf perl
1259     endif
1260   endif
1261 endfunc
1263 " Perl, XPM or XPM2
1264 au BufNewFile,BufRead *.pm
1265         \ if getline(1) =~ "XPM2" |
1266         \   setf xpm2 |
1267         \ elseif getline(1) =~ "XPM" |
1268         \   setf xpm |
1269         \ else |
1270         \   setf perl |
1271         \ endif
1273 " Perl POD
1274 au BufNewFile,BufRead *.pod                     setf pod
1276 " Php, php3, php4, etc.
1277 " Also Phtml (was used for PHP 2 in the past)
1278 " Also .ctp for Cake template file
1279 au BufNewFile,BufRead *.php,*.php\d,*.phtml,*.ctp       setf php
1281 " Pike
1282 au BufNewFile,BufRead *.pike,*.lpc,*.ulpc,*.pmod setf pike
1284 " Pinfo config
1285 au BufNewFile,BufRead */etc/pinforc,*/.pinforc  setf pinfo
1287 " Palm Resource compiler
1288 au BufNewFile,BufRead *.rcp                     setf pilrc
1290 " Pine config
1291 au BufNewFile,BufRead .pinerc,pinerc,.pinercex,pinercex         setf pine
1293 " PL/M (also: *.inp)
1294 au BufNewFile,BufRead *.plm,*.p36,*.pac         setf plm
1296 " PL/SQL
1297 au BufNewFile,BufRead *.pls,*.plsql             setf plsql
1299 " PLP
1300 au BufNewFile,BufRead *.plp                     setf plp
1302 " PO and PO template (GNU gettext)
1303 au BufNewFile,BufRead *.po,*.pot                setf po
1305 " Postfix main config
1306 au BufNewFile,BufRead main.cf                   setf pfmain
1308 " PostScript (+ font files, encapsulated PostScript, Adobe Illustrator)
1309 au BufNewFile,BufRead *.ps,*.pfa,*.afm,*.eps,*.epsf,*.epsi,*.ai   setf postscr
1311 " PostScript Printer Description
1312 au BufNewFile,BufRead *.ppd                     setf ppd
1314 " Povray
1315 au BufNewFile,BufRead *.pov                     setf pov
1317 " Povray configuration
1318 au BufNewFile,BufRead .povrayrc                 setf povini
1320 " Povray, PHP or assembly
1321 au BufNewFile,BufRead *.inc                     call s:FTinc()
1323 func! s:FTinc()
1324   if exists("g:filetype_inc")
1325     exe "setf " . g:filetype_inc
1326   else
1327     let lines = getline(1).getline(2).getline(3)
1328     if lines =~? "perlscript"
1329       setf aspperl
1330     elseif lines =~ "<%"
1331       setf aspvbs
1332     elseif lines =~ "<?"
1333       setf php
1334     else
1335       call s:FTasmsyntax()
1336       if exists("b:asmsyntax")
1337         exe "setf " . b:asmsyntax
1338       else
1339         setf pov
1340       endif
1341     endif
1342   endif
1343 endfunc
1345 " Printcap and Termcap
1346 au BufNewFile,BufRead *printcap
1347         \ let b:ptcap_type = "print" | setf ptcap
1348 au BufNewFile,BufRead *termcap
1349         \ let b:ptcap_type = "term" | setf ptcap
1351 " PCCTS / ANTRL
1352 "au BufNewFile,BufRead *.g                      setf antrl
1353 au BufNewFile,BufRead *.g                       setf pccts
1355 " PPWizard
1356 au BufNewFile,BufRead *.it,*.ih                 setf ppwiz
1358 " Oracle Pro*C/C++
1359 au BufNewFile,BufRead *.pc                      setf proc
1361 " Privoxy actions file
1362 au BufNewFile,BufRead *.action                  setf privoxy
1364 " Procmail
1365 au BufNewFile,BufRead .procmail,.procmailrc     setf procmail
1367 " Progress or CWEB
1368 au BufNewFile,BufRead *.w                       call s:FTprogress_cweb()
1370 func! s:FTprogress_cweb()
1371   if exists("g:filetype_w")
1372     exe "setf " . g:filetype_w
1373     return
1374   endif
1375   if getline(1) =~ '&ANALYZE' || getline(3) =~ '&GLOBAL-DEFINE'
1376     setf progress
1377   else
1378     setf cweb
1379   endif
1380 endfunc
1382 " Progress or assembly
1383 au BufNewFile,BufRead *.i                       call s:FTprogress_asm()
1385 func! s:FTprogress_asm()
1386   if exists("g:filetype_i")
1387     exe "setf " . g:filetype_i
1388     return
1389   endif
1390   " This function checks for an assembly comment the first ten lines.
1391   " If not found, assume Progress.
1392   let lnum = 1
1393   while lnum <= 10 && lnum < line('$')
1394     let line = getline(lnum)
1395     if line =~ '^\s*;' || line =~ '^\*'
1396       call s:FTasm()
1397       return
1398     elseif line !~ '^\s*$' || line =~ '^/\*'
1399       " Not an empty line: Doesn't look like valid assembly code.
1400       " Or it looks like a Progress /* comment
1401       break
1402     endif
1403     let lnum = lnum + 1
1404   endw
1405   setf progress
1406 endfunc
1408 " Progress or Pascal
1409 au BufNewFile,BufRead *.p                       call s:FTprogress_pascal()
1411 func! s:FTprogress_pascal()
1412   if exists("g:filetype_p")
1413     exe "setf " . g:filetype_p
1414     return
1415   endif
1416   " This function checks for valid Pascal syntax in the first ten lines.
1417   " Look for either an opening comment or a program start.
1418   " If not found, assume Progress.
1419   let lnum = 1
1420   while lnum <= 10 && lnum < line('$')
1421     let line = getline(lnum)
1422     if line =~ '^\s*\(program\|unit\|procedure\|function\|const\|type\|var\)\>'
1423         \ || line =~ '^\s*{' || line =~ '^\s*(\*'
1424       setf pascal
1425       return
1426     elseif line !~ '^\s*$' || line =~ '^/\*'
1427       " Not an empty line: Doesn't look like valid Pascal code.
1428       " Or it looks like a Progress /* comment
1429       break
1430     endif
1431     let lnum = lnum + 1
1432   endw
1433   setf progress
1434 endfunc
1437 " Software Distributor Product Specification File (POSIX 1387.2-1995)
1438 au BufNewFile,BufRead *.psf                     setf psf
1439 au BufNewFile,BufRead INDEX,INFO
1440         \ if getline(1) =~ '^\s*\(distribution\|installed_software\|root\|bundle\|product\)\s*$' |
1441         \   setf psf |
1442         \ endif
1444 " Prolog
1445 au BufNewFile,BufRead *.pdb                     setf prolog
1447 " Promela
1448 au BufNewFile,BufRead *.pml                     setf promela
1450 " Protocols
1451 au BufNewFile,BufRead /etc/protocols            setf protocols
1453 " Pyrex
1454 au BufNewFile,BufRead *.pyx,*.pxd               setf pyrex
1456 " Python
1457 au BufNewFile,BufRead *.py,*.pyw                setf python
1459 " Radiance
1460 au BufNewFile,BufRead *.rad,*.mat               setf radiance
1462 " Ratpoison config/command files
1463 au BufNewFile,BufRead .ratpoisonrc,ratpoisonrc  setf ratpoison
1465 " RCS file
1466 au BufNewFile,BufRead *\,v                      setf rcs
1468 " Readline
1469 au BufNewFile,BufRead .inputrc,inputrc          setf readline
1471 " Registry for MS-Windows
1472 au BufNewFile,BufRead *.reg
1473         \ if getline(1) =~? '^REGEDIT[0-9]*\s*$\|^Windows Registry Editor Version \d*\.\d*\s*$' | setf registry | endif
1475 " Renderman Interface Bytestream
1476 au BufNewFile,BufRead *.rib                     setf rib
1478 " Rexx
1479 au BufNewFile,BufRead *.rexx,*.rex,*.jrexx,*.rxj,*.orx  setf rexx
1481 " R (Splus)
1482 if has("fname_case")
1483   au BufNewFile,BufRead *.s,*.S                 setf r
1484 else
1485   au BufNewFile,BufRead *.s                     setf r
1486 endif
1488 " R Help file
1489 if has("fname_case")
1490   au BufNewFile,BufRead *.rd,*.Rd               setf rhelp
1491 else
1492   au BufNewFile,BufRead *.rd                    setf rhelp
1493 endif
1495 " R noweb file
1496 if has("fname_case")
1497   au BufNewFile,BufRead *.Rnw,*.rnw,*.Snw,*.snw         setf rnoweb
1498 else
1499   au BufNewFile,BufRead *.rnw,*.snw                     setf rnoweb
1500 endif
1502 " Rexx, Rebol or R
1503 au BufNewFile,BufRead *.r,*.R                   call s:FTr()
1505 func! s:FTr()
1506   let max = line("$") > 50 ? 50 : line("$")
1508   for n in range(1, max)
1509     " Rebol is easy to recognize, check for that first
1510     if getline(n) =~? '\<REBOL\>'
1511       setf rebol
1512       return
1513     endif
1514   endfor
1516   for n in range(1, max)
1517     " R has # comments
1518     if getline(n) =~ '^\s*#'
1519       setf r
1520       return
1521     endif
1522     " Rexx has /* comments */
1523     if getline(n) =~ '^\s*/\*'
1524       setf rexx
1525       return
1526     endif
1527   endfor
1529   " Nothing recognized, assume Rexx
1530   setf rexx
1531 endfunc
1533 " Remind
1534 au BufNewFile,BufRead .reminders*               call s:StarSetf('remind')
1536 " Resolv.conf
1537 au BufNewFile,BufRead resolv.conf               setf resolv
1539 " Relax NG Compact
1540 au BufNewFile,BufRead *.rnc                     setf rnc
1542 " RPL/2
1543 au BufNewFile,BufRead *.rpl                     setf rpl
1545 " Robots.txt
1546 au BufNewFile,BufRead robots.txt                setf robots
1548 " Rpcgen
1549 au BufNewFile,BufRead *.x                       setf rpcgen
1551 " reStructuredText Documentation Format
1552 au BufNewFile,BufRead *.rst                     setf rst
1554 " RTF
1555 au BufNewFile,BufRead *.rtf                     setf rtf
1557 " Ruby
1558 au BufNewFile,BufRead *.rb,*.rbw,*.gem,*.gemspec        setf ruby
1560 " Ruby on Rails
1561 au BufNewFile,BufRead *.builder,*.rxml,*.rjs    setf ruby
1563 " Rantfile and Rakefile is like Ruby
1564 au BufNewFile,BufRead [rR]antfile,*.rant,[rR]akefile,*.rake     setf ruby
1566 " S-lang (or shader language!)
1567 au BufNewFile,BufRead *.sl                      setf slang
1569 " Samba config
1570 au BufNewFile,BufRead smb.conf                  setf samba
1572 " SAS script
1573 au BufNewFile,BufRead *.sas                     setf sas
1575 " Sather
1576 au BufNewFile,BufRead *.sa                      setf sather
1578 " Scilab
1579 au BufNewFile,BufRead *.sci,*.sce               setf scilab
1581 " SD: Streaming Descriptors
1582 au BufNewFile,BufRead *.sd                      setf sd
1584 " SDL
1585 au BufNewFile,BufRead *.sdl,*.pr                setf sdl
1587 " sed
1588 au BufNewFile,BufRead *.sed                     setf sed
1590 " Sieve (RFC 3028)
1591 au BufNewFile,BufRead *.siv                     setf sieve
1593 " Sendmail
1594 au BufNewFile,BufRead sendmail.cf               setf sm
1596 " Sendmail .mc files are actually m4.  Could also be MS Message text file.
1597 au BufNewFile,BufRead *.mc                      call s:McSetf()
1599 func! s:McSetf()
1600   " Rely on the file to start with a comment.
1601   " MS message text files use ';', Sendmail files use '#' or 'dnl'
1602   for lnum in range(1, min([line("$"), 20]))
1603     let line = getline(lnum)
1604     if line =~ '^\s*\(#\|dnl\)'
1605       setf m4  " Sendmail .mc file
1606       return
1607     elseif line =~ '^\s*;'
1608       setf msmessages  " MS Message text file
1609       return
1610     endif
1611   endfor
1612   setf m4  " Default: Sendmail .mc file
1613 endfunc
1615 " Services
1616 au BufNewFile,BufRead /etc/services             setf services
1618 " Service Location config
1619 au BufNewFile,BufRead /etc/slp.conf             setf slpconf
1621 " Service Location registration
1622 au BufNewFile,BufRead /etc/slp.reg              setf slpreg
1624 " Service Location SPI
1625 au BufNewFile,BufRead /etc/slp.spi              setf slpspi
1627 " Setserial config
1628 au BufNewFile,BufRead /etc/serial.conf          setf setserial
1630 " SGML
1631 au BufNewFile,BufRead *.sgm,*.sgml
1632         \ if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'linuxdoc' |
1633         \   setf sgmllnx |
1634         \ elseif getline(1) =~ '<!DOCTYPE.*DocBook' || getline(2) =~ '<!DOCTYPE.*DocBook' |
1635         \   let b:docbk_type="sgml" |
1636         \   setf docbk |
1637         \ else |
1638         \   setf sgml |
1639         \ endif
1641 " SGMLDECL
1642 au BufNewFile,BufRead *.decl,*.dcl,*.dec
1643         \ if getline(1).getline(2).getline(3) =~? '^<!SGML' |
1644         \    setf sgmldecl |
1645         \ endif
1647 " SGML catalog file
1648 au BufNewFile,BufRead catalog                   setf catalog
1649 au BufNewFile,BufRead sgml.catalog*             call s:StarSetf('catalog')
1651 " Shell scripts (sh, ksh, bash, bash2, csh); Allow .profile_foo etc.
1652 " Gentoo ebuilds are actually bash scripts
1653 au BufNewFile,BufRead .bashrc*,bashrc,bash.bashrc,.bash_profile*,.bash_logout*,*.bash,*.ebuild call SetFileTypeSH("bash")
1654 au BufNewFile,BufRead .kshrc*,*.ksh call SetFileTypeSH("ksh")
1655 au BufNewFile,BufRead /etc/profile,.profile*,*.sh,*.env call SetFileTypeSH(getline(1))
1657 " Also called from scripts.vim.
1658 func! SetFileTypeSH(name)
1659   if expand("<amatch>") =~ g:ft_ignore_pat
1660     return
1661   endif
1662   if a:name =~ '\<ksh\>'
1663     let b:is_kornshell = 1
1664     if exists("b:is_bash")
1665       unlet b:is_bash
1666     endif
1667     if exists("b:is_sh")
1668       unlet b:is_sh
1669     endif
1670   elseif exists("g:bash_is_sh") || a:name =~ '\<bash\>' || a:name =~ '\<bash2\>'
1671     let b:is_bash = 1
1672     if exists("b:is_kornshell")
1673       unlet b:is_kornshell
1674     endif
1675     if exists("b:is_sh")
1676       unlet b:is_sh
1677     endif
1678   elseif a:name =~ '\<sh\>'
1679     let b:is_sh = 1
1680     if exists("b:is_kornshell")
1681       unlet b:is_kornshell
1682     endif
1683     if exists("b:is_bash")
1684       unlet b:is_bash
1685     endif
1686   endif
1687   call SetFileTypeShell("sh")
1688 endfunc
1690 " For shell-like file types, check for an "exec" command hidden in a comment,
1691 " as used for Tcl.
1692 " Also called from scripts.vim, thus can't be local to this script.
1693 func! SetFileTypeShell(name)
1694   if expand("<amatch>") =~ g:ft_ignore_pat
1695     return
1696   endif
1697   let l = 2
1698   while l < 20 && l < line("$") && getline(l) =~ '^\s*\(#\|$\)'
1699     " Skip empty and comment lines.
1700     let l = l + 1
1701   endwhile
1702   if l < line("$") && getline(l) =~ '\s*exec\s' && getline(l - 1) =~ '^\s*#.*\\$'
1703     " Found an "exec" line after a comment with continuation
1704     let n = substitute(getline(l),'\s*exec\s\+\([^ ]*/\)\=', '', '')
1705     if n =~ '\<tclsh\|\<wish'
1706       setf tcl
1707       return
1708     endif
1709   endif
1710   exe "setf " . a:name
1711 endfunc
1713 " tcsh scripts
1714 au BufNewFile,BufRead .tcshrc*,*.tcsh,tcsh.tcshrc,tcsh.login    call SetFileTypeShell("tcsh")
1716 " csh scripts, but might also be tcsh scripts (on some systems csh is tcsh)
1717 au BufNewFile,BufRead .login*,.cshrc*,csh.cshrc,csh.login,csh.logout,*.csh,.alias  call s:CSH()
1719 func! s:CSH()
1720   if exists("g:filetype_csh")
1721     call SetFileTypeShell(g:filetype_csh)
1722   elseif &shell =~ "tcsh"
1723     call SetFileTypeShell("tcsh")
1724   else
1725     call SetFileTypeShell("csh")
1726   endif
1727 endfunc
1729 " Z-Shell script
1730 au BufNewFile,BufRead .zprofile,/etc/zprofile,.zfbfmarks  setf zsh
1731 au BufNewFile,BufRead .zsh*,.zlog*,.zcompdump*  call s:StarSetf('zsh')
1733 " Scheme
1734 au BufNewFile,BufRead *.scm,*.ss                setf scheme
1736 " Screen RC
1737 au BufNewFile,BufRead .screenrc,screenrc        setf screen
1739 " Simula
1740 au BufNewFile,BufRead *.sim                     setf simula
1742 " SINDA
1743 au BufNewFile,BufRead *.sin,*.s85               setf sinda
1745 " SiSU
1746 au BufNewFile,BufRead *.sst,*.ssm,*.ssi,*.-sst,*._sst setf sisu
1747 au BufNewFile,BufRead *.sst.meta,*.-sst.meta,*._sst.meta setf sisu
1749 " SKILL
1750 au BufNewFile,BufRead *.il,*.ils,*.cdf          setf skill
1752 " SLRN
1753 au BufNewFile,BufRead .slrnrc                   setf slrnrc
1754 au BufNewFile,BufRead *.score                   setf slrnsc
1756 " Smalltalk (and TeX)
1757 au BufNewFile,BufRead *.st                      setf st
1758 au BufNewFile,BufRead *.cls
1759         \ if getline(1) =~ '^%' |
1760         \  setf tex |
1761         \ else |
1762         \  setf st |
1763         \ endif
1765 " Smarty templates
1766 au BufNewFile,BufRead *.tpl                     setf smarty
1768 " SMIL or XML
1769 au BufNewFile,BufRead *.smil
1770         \ if getline(1) =~ '<?\s*xml.*?>' |
1771         \   setf xml |
1772         \ else |
1773         \   setf smil |
1774         \ endif
1776 " SMIL or SNMP MIB file
1777 au BufNewFile,BufRead *.smi
1778         \ if getline(1) =~ '\<smil\>' |
1779         \   setf smil |
1780         \ else |
1781         \   setf mib |
1782         \ endif
1784 " SMITH
1785 au BufNewFile,BufRead *.smt,*.smith             setf smith
1787 " Snobol4 and spitbol
1788 au BufNewFile,BufRead *.sno,*.spt               setf snobol4
1790 " SNMP MIB files
1791 au BufNewFile,BufRead *.mib,*.my                setf mib
1793 " Snort Configuration
1794 au BufNewFile,BufRead *.hog,snort.conf,vision.conf      setf hog
1795 au BufNewFile,BufRead *.rules                   call s:FTRules()
1797 let s:ft_rules_udev_rules_pattern = '^\s*\cudev_rules\s*=\s*"\([^"]\{-1,}\)/*".*'
1798 func! s:FTRules()
1799   if expand('<amatch>:p') =~ '^/etc/udev/rules\.d/.*\.rules$'
1800     setf udevrules
1801     return
1802   endif
1803   try
1804     let config_lines = readfile('/etc/udev/udev.conf')
1805   catch /^Vim\%((\a\+)\)\=:E484/
1806     setf hog
1807     return
1808   endtry
1809   let dir = expand('<amatch>:p:h')
1810   for line in config_lines
1811     if line =~ s:ft_rules_udev_rules_pattern
1812       let udev_rules = substitute(line, s:ft_rules_udev_rules_pattern, '\1', "")
1813       if dir == udev_rules
1814         setf udevrules
1815       endif
1816       break
1817     endif
1818   endfor
1819   setf hog
1820 endfunc
1823 " Spec (Linux RPM)
1824 au BufNewFile,BufRead *.spec                    setf spec
1826 " Speedup (AspenTech plant simulator)
1827 au BufNewFile,BufRead *.speedup,*.spdata,*.spd  setf spup
1829 " Slice
1830 au BufNewFile,BufRead *.ice                     setf slice
1832 " Spice
1833 au BufNewFile,BufRead *.sp,*.spice              setf spice
1835 " Spyce
1836 au BufNewFile,BufRead *.spy,*.spi               setf spyce
1838 " Squid
1839 au BufNewFile,BufRead squid.conf                setf squid
1841 " SQL for Oracle Designer
1842 au BufNewFile,BufRead *.tyb,*.typ,*.tyc,*.pkb,*.pks     setf sql
1844 " SQL
1845 au BufNewFile,BufRead *.sql                     call s:SQL()
1847 func! s:SQL()
1848   if exists("g:filetype_sql")
1849     exe "setf " . g:filetype_sql
1850   else
1851     setf sql
1852   endif
1853 endfunc
1855 " SQLJ
1856 au BufNewFile,BufRead *.sqlj                    setf sqlj
1858 " SQR
1859 au BufNewFile,BufRead *.sqr,*.sqi               setf sqr
1861 " OpenSSH configuration
1862 au BufNewFile,BufRead ssh_config,*/.ssh/config  setf sshconfig
1864 " OpenSSH server configuration
1865 au BufNewFile,BufRead sshd_config               setf sshdconfig
1867 " Stata
1868 au BufNewFile,BufRead *.ado,*.class,*.do,*.imata,*.mata   setf stata
1870 " SMCL
1871 au BufNewFile,BufRead *.hlp,*.ihlp,*.smcl       setf smcl
1873 " Stored Procedures
1874 au BufNewFile,BufRead *.stp                     setf stp
1876 " Standard ML
1877 au BufNewFile,BufRead *.sml                     setf sml
1879 " Sratus VOS command macro
1880 au BufNewFile,BufRead *.cm                      setf voscm
1882 " Sysctl
1883 au BufNewFile,BufRead /etc/sysctl.conf          setf sysctl
1885 " Sudoers
1886 au BufNewFile,BufRead /etc/sudoers,sudoers.tmp  setf sudoers
1888 " If the file has an extension of 't' and is in a directory 't' then it is
1889 " almost certainly a Perl test file.
1890 " If the first line starts with '#' and contains 'perl' it's probably a Perl
1891 " file.
1892 " (Slow test) If a file contains a 'use' statement then it is almost certainly
1893 " a Perl file.
1894 func! s:FTperl()
1895   if expand("%:e") == 't' && expand("%:p:h:t") == 't'
1896     setf perl
1897     return 1
1898   endif
1899   if getline(1)[0] == '#' && getline(1) =~ 'perl'
1900     setf perl
1901     return 1
1902   endif
1903   if search('^use\s\s*\k', 'nc', 30)
1904     setf perl
1905     return 1
1906   endif
1907   return 0
1908 endfunc
1910 " Tads (or Nroff or Perl test file)
1911 au BufNewFile,BufRead *.t
1912         \ if !s:FTnroff() && !s:FTperl() | setf tads | endif
1914 " Tags
1915 au BufNewFile,BufRead tags                      setf tags
1917 " TAK
1918 au BufNewFile,BufRead *.tak                     setf tak
1920 " Tcl (JACL too)
1921 au BufNewFile,BufRead *.tcl,*.tk,*.itcl,*.itk,*.jacl    setf tcl
1923 " TealInfo
1924 au BufNewFile,BufRead *.tli                     setf tli
1926 " Telix Salt
1927 au BufNewFile,BufRead *.slt                     setf tsalt
1929 " Terminfo
1930 au BufNewFile,BufRead *.ti                      setf terminfo
1932 " TeX
1933 au BufNewFile,BufRead *.latex,*.sty,*.dtx,*.ltx,*.bbl   setf tex
1934 au BufNewFile,BufRead *.tex                     call s:FTtex()
1936 " Choose context, plaintex, or tex (LaTeX) based on these rules:
1937 " 1. Check the first line of the file for "%&<format>".
1938 " 2. Check the first 1000 non-comment lines for LaTeX or ConTeXt keywords.
1939 " 3. Default to "latex" or to g:tex_flavor, can be set in user's vimrc.
1940 func! s:FTtex()
1941   let firstline = getline(1)
1942   if firstline =~ '^%&\s*\a\+'
1943     let format = tolower(matchstr(firstline, '\a\+'))
1944     let format = substitute(format, 'pdf', '', '')
1945     if format == 'tex'
1946       let format = 'plain'
1947     endif
1948   else
1949     " Default value, may be changed later:
1950     let format = exists("g:tex_flavor") ? g:tex_flavor : 'plain'
1951     " Save position, go to the top of the file, find first non-comment line.
1952     let save_cursor = getpos('.')
1953     call cursor(1,1)
1954     let firstNC = search('^\s*[^[:space:]%]', 'c', 1000)
1955     if firstNC " Check the next thousand lines for a LaTeX or ConTeXt keyword.
1956       let lpat = 'documentclass\>\|usepackage\>\|begin{\|newcommand\>\|renewcommand\>'
1957       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\>'
1958       let kwline = search('^\s*\\\%(' . lpat . '\)\|^\s*\\\(' . cpat . '\)',
1959                               \ 'cnp', firstNC + 1000)
1960       if kwline == 1    " lpat matched
1961         let format = 'latex'
1962       elseif kwline == 2        " cpat matched
1963         let format = 'context'
1964       endif             " If neither matched, keep default set above.
1965       " let lline = search('^\s*\\\%(' . lpat . '\)', 'cn', firstNC + 1000)
1966       " let cline = search('^\s*\\\%(' . cpat . '\)', 'cn', firstNC + 1000)
1967       " if cline > 0
1968       "   let format = 'context'
1969       " endif
1970       " if lline > 0 && (cline == 0 || cline > lline)
1971       "   let format = 'tex'
1972       " endif
1973     endif " firstNC
1974     call setpos('.', save_cursor)
1975   endif " firstline =~ '^%&\s*\a\+'
1977   " Translation from formats to file types.  TODO:  add AMSTeX, RevTex, others?
1978   if format == 'plain'
1979     setf plaintex
1980   elseif format == 'context'
1981     setf context
1982   else " probably LaTeX
1983     setf tex
1984   endif
1985   return
1986 endfunc
1988 " ConTeXt
1989 au BufNewFile,BufRead tex/context/*/*.tex,*.mkii,*.mkiv   setf context
1991 " Texinfo
1992 au BufNewFile,BufRead *.texinfo,*.texi,*.txi    setf texinfo
1994 " TeX configuration
1995 au BufNewFile,BufRead texmf.cnf                 setf texmf
1997 " Tidy config
1998 au BufNewFile,BufRead .tidyrc,tidyrc            setf tidy
2000 " TF mud client
2001 au BufNewFile,BufRead *.tf,.tfrc,tfrc           setf tf
2003 " TPP - Text Presentation Program
2004 au BufNewFile,BufReadPost *.tpp                 setf tpp
2006 " Trustees
2007 au BufNewFile,BufRead trustees.conf             setf trustees
2009 " TSS - Geometry
2010 au BufNewFile,BufReadPost *.tssgm               setf tssgm
2012 " TSS - Optics
2013 au BufNewFile,BufReadPost *.tssop               setf tssop
2015 " TSS - Command Line (temporary)
2016 au BufNewFile,BufReadPost *.tsscl               setf tsscl
2018 " Motif UIT/UIL files
2019 au BufNewFile,BufRead *.uit,*.uil               setf uil
2021 " Udev conf
2022 au BufNewFile,BufRead /etc/udev/udev.conf       setf udevconf
2024 " Udev permissions
2025 au BufNewFile,BufRead /etc/udev/permissions.d/*.permissions setf udevperm
2027 " Udev symlinks config
2028 au BufNewFile,BufRead /etc/udev/cdsymlinks.conf setf sh
2030 " UnrealScript
2031 au BufNewFile,BufRead *.uc                      setf uc
2033 " Updatedb
2034 au BufNewFile,BufRead /etc/updatedb.conf        setf updatedb
2036 " Vera
2037 au BufNewFile,BufRead *.vr,*.vri,*.vrh          setf vera
2039 " Verilog HDL
2040 au BufNewFile,BufRead *.v                       setf verilog
2042 " Verilog-AMS HDL
2043 au BufNewFile,BufRead *.va,*.vams               setf verilogams
2045 " VHDL
2046 au BufNewFile,BufRead *.hdl,*.vhd,*.vhdl,*.vbe,*.vst  setf vhdl
2047 au BufNewFile,BufRead *.vhdl_[0-9]*             call s:StarSetf('vhdl')
2049 " Vim script
2050 au BufNewFile,BufRead *.vim,*.vba,.exrc,_exrc   setf vim
2052 " Viminfo file
2053 au BufNewFile,BufRead .viminfo,_viminfo         setf viminfo
2055 " Virata Config Script File
2056 au BufRead,BufNewFile *.hw,*.module,*.pkg       setf virata
2058 " Visual Basic (also uses *.bas) or FORM
2059 au BufNewFile,BufRead *.frm                     call s:FTVB("form")
2061 " SaxBasic is close to Visual Basic
2062 au BufNewFile,BufRead *.sba                     setf vb
2064 " Vgrindefs file
2065 au BufNewFile,BufRead vgrindefs                 setf vgrindefs
2067 " VRML V1.0c
2068 au BufNewFile,BufRead *.wrl                     setf vrml
2070 " Webmacro
2071 au BufNewFile,BufRead *.wm                      setf webmacro
2073 " Wget config
2074 au BufNewFile,BufRead .wgetrc,wgetrc            setf wget
2076 " Website MetaLanguage
2077 au BufNewFile,BufRead *.wml                     setf wml
2079 " Winbatch
2080 au BufNewFile,BufRead *.wbt                     setf winbatch
2082 " WSML
2083 au BufNewFile,BufRead *.wsml                    setf wsml
2085 " WvDial
2086 au BufNewFile,BufRead wvdial.conf,.wvdialrc     setf wvdial
2088 " CVS RC file
2089 au BufNewFile,BufRead .cvsrc                    setf cvsrc
2091 " CVS commit file
2092 au BufNewFile,BufRead cvs\d\+                   setf cvs
2094 " WEB (*.web is also used for Winbatch: Guess, based on expecting "%" comment
2095 " lines in a WEB file).
2096 au BufNewFile,BufRead *.web
2097         \ if getline(1)[0].getline(2)[0].getline(3)[0].getline(4)[0].getline(5)[0] =~ "%" |
2098         \   setf web |
2099         \ else |
2100         \   setf winbatch |
2101         \ endif
2103 " Windows Scripting Host and Windows Script Component
2104 au BufNewFile,BufRead *.ws[fc]                  setf wsh
2106 " XHTML
2107 au BufNewFile,BufRead *.xhtml,*.xht             setf xhtml
2109 " X Pixmap (dynamically sets colors, use BufEnter to make it work better)
2110 au BufEnter *.xpm
2111         \ if getline(1) =~ "XPM2" |
2112         \   setf xpm2 |
2113         \ else |
2114         \   setf xpm |
2115         \ endif
2116 au BufEnter *.xpm2                              setf xpm2
2118 " XFree86 config
2119 au BufNewFile,BufRead XF86Config
2120         \ if getline(1) =~ '\<XConfigurator\>' |
2121         \   let b:xf86c_xfree86_version = 3 |
2122         \ endif |
2123         \ setf xf86conf
2125 " Xorg config
2126 au BufNewFile,BufRead xorg.conf,xorg.conf-4     let b:xf86c_xfree86_version = 4 | setf xf86conf
2128 " Xinetd conf
2129 au BufNewFile,BufRead /etc/xinetd.conf          setf xinetd
2131 " XS Perl extension interface language
2132 au BufNewFile,BufRead *.xs                      setf xs
2134 " X resources file
2135 au BufNewFile,BufRead .Xdefaults,.Xpdefaults,.Xresources,xdm-config,*.ad setf xdefaults
2137 " Xmath
2138 au BufNewFile,BufRead *.msc,*.msf               setf xmath
2139 au BufNewFile,BufRead *.ms
2140         \ if !s:FTnroff() | setf xmath | endif
2142 " XML  specific variants: docbk and xbl
2143 au BufNewFile,BufRead *.xml                     call s:FTxml()
2145 func! s:FTxml()
2146   let n = 1
2147   while n < 100 && n < line("$")
2148     let line = getline(n)
2149     if line =~ '<!DOCTYPE.*DocBook'
2150       let b:docbk_type = "xml"
2151       setf docbk
2152       return
2153     endif
2154     if line =~ 'xmlns:xbl="http://www.mozilla.org/xbl"'
2155       setf xbl
2156       return
2157     endif
2158     let n += 1
2159   endwhile
2160   setf xml
2161 endfunc
2163 " XMI (holding UML models) is also XML
2164 au BufNewFile,BufRead *.xmi                     setf xml
2166 " CSPROJ files are Visual Studio.NET's XML-based project config files
2167 au BufNewFile,BufRead *.csproj,*.csproj.user    setf xml
2169 " Qt Linguist translation source and Qt User Interface Files are XML
2170 au BufNewFile,BufRead *.ts,*.ui                 setf xml
2172 " TPM's are RDF-based descriptions of TeX packages (Nikolai Weibull)
2173 au BufNewFile,BufRead *.tpm                     setf xml
2175 " Xdg menus
2176 au BufNewFile,BufRead /etc/xdg/menus/*.menu     setf xml
2178 " ATI graphics driver configuration
2179 au BufNewFile,BufRead fglrxrc                   setf xml
2181 " XLIFF (XML Localisation Interchange File Format) is also XML
2182 au BufNewFile,BufRead *.xlf                     setf xml
2183 au BufNewFile,BufRead *.xliff                   setf xml
2185 " X11 xmodmap (also see below)
2186 au BufNewFile,BufRead *Xmodmap                  setf xmodmap
2188 " Xquery
2189 au BufNewFile,BufRead *.xq,*.xql,*.xqm,*.xquery,*.xqy   setf xquery
2191 " XSD
2192 au BufNewFile,BufRead *.xsd                     setf xsd
2194 " Xslt
2195 au BufNewFile,BufRead *.xsl,*.xslt              setf xslt
2197 " Yacc
2198 au BufNewFile,BufRead *.yy                      setf yacc
2200 " Yacc or racc
2201 au BufNewFile,BufRead *.y                       call s:FTy()
2203 func! s:FTy()
2204   let n = 1
2205   while n < 100 && n < line("$")
2206     let line = getline(n)
2207     if line =~ '^\s*%'
2208       setf yacc
2209       return
2210     endif
2211     if getline(n) =~ '^\s*\(#\|class\>\)' && getline(n) !~ '^\s*#\s*include'
2212       setf racc
2213       return
2214     endif
2215     let n = n + 1
2216   endwhile
2217   setf yacc
2218 endfunc
2221 " Yaml
2222 au BufNewFile,BufRead *.yaml,*.yml              setf yaml
2224 " Zope
2225 "   dtml (zope dynamic template markup language), pt (zope page template),
2226 "   cpt (zope form controller page template)
2227 au BufNewFile,BufRead *.dtml,*.pt,*.cpt         call s:FThtml()
2228 "   zsql (zope sql method)
2229 au BufNewFile,BufRead *.zsql                    call s:SQL()
2231 " Z80 assembler asz80
2232 au BufNewFile,BufRead *.z8a                     setf z8a
2234 augroup END
2237 " Source the user-specified filetype file, for backwards compatibility with
2238 " Vim 5.x.
2239 if exists("myfiletypefile") && filereadable(expand(myfiletypefile))
2240   execute "source " . myfiletypefile
2241 endif
2244 " Check for "*" after loading myfiletypefile, so that scripts.vim is only used
2245 " when there are no matching file name extensions.
2246 " Don't do this for compressed files.
2247 augroup filetypedetect
2248 au BufNewFile,BufRead *
2249         \ if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat
2250         \ | runtime! scripts.vim | endif
2251 au StdinReadPost * if !did_filetype() | runtime! scripts.vim | endif
2254 " Extra checks for when no filetype has been detected now.  Mostly used for
2255 " patterns that end in "*".  E.g., "zsh*" matches "zsh.vim", but that's a Vim
2256 " script file.
2257 " Most of these should call s:StarSetf() to avoid names ending in .gz and the
2258 " like are used.
2260 " Asterisk config file
2261 au BufNewFile,BufRead *asterisk/*.conf*         call s:StarSetf('asterisk')
2262 au BufNewFile,BufRead *asterisk*/*voicemail.conf* call s:StarSetf('asteriskvm')
2264 " Bazaar version control
2265 au BufNewFile,BufRead bzr_log.*                 setf bzr
2267 " BIND zone
2268 au BufNewFile,BufRead */named/db.*,*/bind/db.*  call s:StarSetf('bindzone')
2270 " Changelog
2271 au BufNewFile,BufRead [cC]hange[lL]og*
2272         \ if getline(1) =~ '; urgency='
2273         \|  call s:StarSetf('debchangelog')
2274         \|else
2275         \|  call s:StarSetf('changelog')
2276         \|endif
2278 " Crontab
2279 au BufNewFile,BufRead crontab,crontab.*         call s:StarSetf('crontab')
2281 " Debian Sources.list
2282 au BufNewFile,BufRead /etc/apt/sources.list.d/* call s:StarSetf('debsources')
2284 " Dracula
2285 au BufNewFile,BufRead drac.*                    call s:StarSetf('dracula')
2287 " Fvwm
2288 au BufNewFile,BufRead */.fvwm/*                 call s:StarSetf('fvwm')
2289 au BufNewFile,BufRead *fvwmrc*,*fvwm95*.hook
2290         \ let b:fvwm_version = 1 | call s:StarSetf('fvwm')
2291 au BufNewFile,BufRead *fvwm2rc*
2292         \ if expand("<afile>:e") == "m4"
2293         \|  call s:StarSetf('fvwm2m4')
2294         \|else
2295         \|  let b:fvwm_version = 2 | call s:StarSetf('fvwm')
2296         \|endif
2298 " GTK RC
2299 au BufNewFile,BufRead .gtkrc*,gtkrc*            call s:StarSetf('gtkrc')
2301 " Jam
2302 au BufNewFile,BufRead Prl*.*,JAM*.*             call s:StarSetf('jam')
2304 " Jargon
2305 au! BufNewFile,BufRead *jarg*
2306         \ if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'THIS IS THE JARGON FILE'
2307         \|  call s:StarSetf('jargon')
2308         \|endif
2310 " Kconfig
2311 au BufNewFile,BufRead Kconfig.*                 call s:StarSetf('kconfig')
2313 " Makefile
2314 au BufNewFile,BufRead [mM]akefile*              call s:StarSetf('make')
2316 " Ruby Makefile
2317 au BufNewFile,BufRead [rR]akefile*              call s:StarSetf('ruby')
2319 " Mail (also matches muttrc.vim, so this is below the other checks)
2320 au BufNewFile,BufRead mutt[[:alnum:]._-]\{6\}   setf mail
2322 " Modconf
2323 au BufNewFile,BufRead /etc/modprobe.*           call s:StarSetf('modconf')
2325 " Mutt setup file
2326 au BufNewFile,BufRead .mutt{ng,}rc*,*/.mutt{ng,}/mutt{ng,}rc*   call s:StarSetf('muttrc')
2327 au BufNewFile,BufRead mutt{ng,}rc*,Mutt{ng,}rc*         call s:StarSetf('muttrc')
2329 " Nroff macros
2330 au BufNewFile,BufRead tmac.*                    call s:StarSetf('nroff')
2332 " Pam conf
2333 au BufNewFile,BufRead /etc/pam.d/*              call s:StarSetf('pamconf')
2335 " Printcap and Termcap
2336 au BufNewFile,BufRead *printcap*
2337         \ if !did_filetype()
2338         \|  let b:ptcap_type = "print" | call s:StarSetf('ptcap')
2339         \|endif
2340 au BufNewFile,BufRead *termcap*
2341         \ if !did_filetype()
2342         \|  let b:ptcap_type = "term" | call s:StarSetf('ptcap')
2343         \|endif
2345 " Vim script
2346 au BufNewFile,BufRead *vimrc*                   call s:StarSetf('vim')
2348 " Subversion commit file
2349 au BufNewFile,BufRead svn-commit*.tmp           setf svn
2351 " X resources file
2352 au BufNewFile,BufRead Xresources*,*/app-defaults/*,*/Xresources/* call s:StarSetf('xdefaults')
2354 " XFree86 config
2355 au BufNewFile,BufRead XF86Config-4*
2356         \ let b:xf86c_xfree86_version = 4 | call s:StarSetf('xf86conf')
2357 au BufNewFile,BufRead XF86Config*
2358         \ if getline(1) =~ '\<XConfigurator\>'
2359         \|  let b:xf86c_xfree86_version = 3
2360         \|endif
2361         \|call s:StarSetf('xf86conf')
2363 " X11 xmodmap
2364 au BufNewFile,BufRead *xmodmap*                 call s:StarSetf('xmodmap')
2366 " Xinetd conf
2367 au BufNewFile,BufRead /etc/xinetd.d/*           call s:StarSetf('xinetd')
2369 " Z-Shell script
2370 au BufNewFile,BufRead zsh*,zlog*                call s:StarSetf('zsh')
2373 " Generic configuration file (check this last, it's just guessing!)
2374 au BufNewFile,BufRead,StdinReadPost *
2375         \ if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat
2376         \    && (getline(1) =~ '^#' || getline(2) =~ '^#' || getline(3) =~ '^#'
2377         \       || getline(4) =~ '^#' || getline(5) =~ '^#') |
2378         \   setf conf |
2379         \ endif
2381 " Use the plugin-filetype checks last, they may overrule any of the previously
2382 " detected filetypes.
2383 runtime! ftdetect/*.vim
2385 augroup END
2388 " If the GUI is already running, may still need to install the Syntax menu.
2389 " Don't do it when the 'M' flag is included in 'guioptions'.
2390 if has("menu") && has("gui_running")
2391       \ && !exists("did_install_syntax_menu") && &guioptions !~# "M"
2392   source <sfile>:p:h/menu.vim
2393 endif
2395 " Function called for testing all functions defined here.  These are
2396 " script-local, thus need to be executed here.
2397 " Returns a string with error messages (hopefully empty).
2398 func! TestFiletypeFuncs(testlist)
2399   let output = ''
2400   for f in a:testlist
2401     try
2402       exe f
2403     catch
2404       let output = output . "\n" . f . ": " . v:exception
2405     endtry
2406   endfor
2407   return output
2408 endfunc
2410 " Restore 'cpoptions'
2411 let &cpo = s:cpo_save
2412 unlet s:cpo_save