Add clipboard support in non-GUI mode
[MacVim.git] / runtime / filetype.vim
blob81d4db30bf75f27b34ec1ad1d465f404811af5e9
1 " Vim support file to detect file types
3 " Maintainer:   Bram Moolenaar <Bram@vim.org>
4 " Last Change:  2008 Nov 01
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 " Applescript
120 au BufNewFile,BufRead *.scpt                    setf applescript
122 " Applix ELF
123 au BufNewFile,BufRead *.am
124         \ if expand("<afile>") !~? 'Makefile.am\>' | setf elf | endif
126 " ALSA configuration
127 au BufNewFile,BufRead ~/.asoundrc,/usr/share/alsa/alsa.conf,/etc/asound.conf    setf alsaconf
129 " Arc Macro Language
130 au BufNewFile,BufRead *.aml                     setf aml
132 " Arch Inventory file
133 au BufNewFile,BufRead .arch-inventory,=tagging-method   setf arch
135 " ART*Enterprise (formerly ART-IM)
136 au BufNewFile,BufRead *.art                     setf art
138 " ASN.1
139 au BufNewFile,BufRead *.asn,*.asn1              setf asn
141 " Active Server Pages (with Visual Basic Script)
142 au BufNewFile,BufRead *.asa
143         \ if exists("g:filetype_asa") |
144         \   exe "setf " . g:filetype_asa |
145         \ else |
146         \   setf aspvbs |
147         \ endif
149 " Active Server Pages (with Perl or Visual Basic Script)
150 au BufNewFile,BufRead *.asp
151         \ if exists("g:filetype_asp") |
152         \   exe "setf " . g:filetype_asp |
153         \ elseif getline(1) . getline(2) . getline(3) =~? "perlscript" |
154         \   setf aspperl |
155         \ else |
156         \   setf aspvbs |
157         \ endif
159 " Grub (must be before catch *.lst)
160 au BufNewFile,BufRead /boot/grub/menu.lst,/boot/grub/grub.conf,/etc/grub.conf   setf grub
162 " Assembly (all kinds)
163 " *.lst is not pure assembly, it has two extra columns (address, byte codes)
164 au BufNewFile,BufRead *.asm,*.[sS],*.[aA],*.mac,*.lst   call s:FTasm()
166 " This function checks for the kind of assembly that is wanted by the user, or
167 " can be detected from the first five lines of the file.
168 func! s:FTasm()
169   " make sure b:asmsyntax exists
170   if !exists("b:asmsyntax")
171     let b:asmsyntax = ""
172   endif
174   if b:asmsyntax == ""
175     call s:FTasmsyntax()
176   endif
178   " if b:asmsyntax still isn't set, default to asmsyntax or GNU
179   if b:asmsyntax == ""
180     if exists("g:asmsyntax")
181       let b:asmsyntax = g:asmsyntax
182     else
183       let b:asmsyntax = "asm"
184     endif
185   endif
187   exe "setf " . fnameescape(b:asmsyntax)
188 endfunc
190 func! s:FTasmsyntax()
191   " see if file contains any asmsyntax=foo overrides. If so, change
192   " b:asmsyntax appropriately
193   let head = " ".getline(1)." ".getline(2)." ".getline(3)." ".getline(4).
194         \" ".getline(5)." "
195   let match = matchstr(head, '\sasmsyntax=\zs[a-zA-Z0-9]\+\ze\s')
196   if match != ''
197     let b:asmsyntax = match
198   elseif ((head =~? '\.title') || (head =~? '\.ident') || (head =~? '\.macro') || (head =~? '\.subtitle') || (head =~? '\.library'))
199     let b:asmsyntax = "vmasm"
200   endif
201 endfunc
203 " Macro (VAX)
204 au BufNewFile,BufRead *.mar                     setf vmasm
206 " Atlas
207 au BufNewFile,BufRead *.atl,*.as                setf atlas
209 " Autoit v3
210 au BufNewFile,BufRead *.au3                     setf autoit
212 " Autohotkey
213 au BufNewFile,BufRead *.ahk                     setf autohotkey
215 " Automake
216 au BufNewFile,BufRead [mM]akefile.am,GNUmakefile.am     setf automake
218 " Autotest .at files are actually m4
219 au BufNewFile,BufRead *.at                      setf m4
221 " Avenue
222 au BufNewFile,BufRead *.ave                     setf ave
224 " Awk
225 au BufNewFile,BufRead *.awk                     setf awk
227 " B
228 au BufNewFile,BufRead *.mch,*.ref,*.imp         setf b
230 " BASIC or Visual Basic
231 au BufNewFile,BufRead *.bas                     call s:FTVB("basic")
233 " Check if one of the first five lines contains "VB_Name".  In that case it is
234 " probably a Visual Basic file.  Otherwise it's assumed to be "alt" filetype.
235 func! s:FTVB(alt)
236   if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'VB_Name\|Begin VB\.\(Form\|MDIForm\|UserControl\)'
237     setf vb
238   else
239     exe "setf " . a:alt
240   endif
241 endfunc
243 " Visual Basic Script (close to Visual Basic)
244 au BufNewFile,BufRead *.vbs,*.dsm,*.ctl         setf vb
246 " IBasic file (similar to QBasic)
247 au BufNewFile,BufRead *.iba,*.ibi               setf ibasic
249 " FreeBasic file (similar to QBasic)
250 au BufNewFile,BufRead *.fb,*.bi                 setf freebasic
252 " Batch file for MSDOS.
253 au BufNewFile,BufRead *.bat,*.sys               setf dosbatch
254 " *.cmd is close to a Batch file, but on OS/2 Rexx files also use *.cmd.
255 au BufNewFile,BufRead *.cmd
256         \ if getline(1) =~ '^/\*' | setf rexx | else | setf dosbatch | endif
258 " Batch file for 4DOS
259 au BufNewFile,BufRead *.btm                     call s:FTbtm()
260 func! s:FTbtm()
261   if exists("g:dosbatch_syntax_for_btm") && g:dosbatch_syntax_for_btm
262     setf dosbatch
263   else
264     setf btm
265   endif
266 endfunc
268 " BC calculator
269 au BufNewFile,BufRead *.bc                      setf bc
271 " BDF font
272 au BufNewFile,BufRead *.bdf                     setf bdf
274 " BibTeX bibliography database file
275 au BufNewFile,BufRead *.bib                     setf bib
277 " BibTeX Bibliography Style
278 au BufNewFile,BufRead *.bst                     setf bst
280 " BIND configuration
281 au BufNewFile,BufRead named.conf,rndc.conf      setf named
283 " BIND zone
284 au BufNewFile,BufRead named.root                setf bindzone
285 au BufNewFile,BufRead *.db                      call s:BindzoneCheck('')
287 func! s:BindzoneCheck(default)
288   if getline(1).getline(2).getline(3).getline(4) =~ '^; <<>> DiG [0-9.]\+ <<>>\|BIND.*named\|$ORIGIN\|$TTL\|IN\s\+SOA'
289     setf bindzone
290   elseif a:default != ''
291     exe 'setf ' . a:default
292   endif
293 endfunc
295 " Blank
296 au BufNewFile,BufRead *.bl                      setf blank
298 " Blkid cache file
299 au BufNewFile,BufRead /etc/blkid.tab,/etc/blkid.tab.old   setf xml
301 " C or lpc
302 au BufNewFile,BufRead *.c                       call s:FTlpc()
304 func! s:FTlpc()
305   if exists("g:lpc_syntax_for_c")
306     let lnum = 1
307     while lnum <= 12
308       if getline(lnum) =~# '^\(//\|inherit\|private\|protected\|nosave\|string\|object\|mapping\|mixed\)'
309         setf lpc
310         return
311       endif
312       let lnum = lnum + 1
313     endwhile
314   endif
315   setf c
316 endfunc
318 " Calendar
319 au BufNewFile,BufRead calendar                  setf calendar
320 au BufNewFile,BufRead */.calendar/*,
321         \*/share/calendar/*/calendar.*,*/share/calendar/calendar.*
322         \                                       call s:StarSetf('calendar')
324 " C#
325 au BufNewFile,BufRead *.cs                      setf cs
327 " Cdrdao TOC
328 au BufNewFile,BufRead *.toc                     setf cdrtoc
330 " Cdrdao config
331 au BufNewFile,BufRead etc/cdrdao.conf,etc/defaults/cdrdao,etc/default/cdrdao,~/.cdrdao                                          setf cdrdaoconf
333 " Cfengine
334 au BufNewFile,BufRead cfengine.conf             setf cfengine
336 " Comshare Dimension Definition Language
337 au BufNewFile,BufRead *.cdl                     setf cdl
339 " Conary Recipe
340 au BufNewFile,BufRead *.recipe                  setf conaryrecipe
342 " Controllable Regex Mutilator
343 au BufNewFile,BufRead *.crm                     setf crm
345 " Cyn++
346 au BufNewFile,BufRead *.cyn                     setf cynpp
348 " Cynlib
349 " .cc and .cpp files can be C++ or Cynlib.
350 au BufNewFile,BufRead *.cc
351         \ if exists("cynlib_syntax_for_cc")|setf cynlib|else|setf cpp|endif
352 au BufNewFile,BufRead *.cpp
353         \ if exists("cynlib_syntax_for_cpp")|setf cynlib|else|setf cpp|endif
355 " C++
356 au BufNewFile,BufRead *.cxx,*.c++,*.hh,*.hxx,*.hpp,*.ipp,*.moc,*.tcc,*.inl setf cpp
357 if has("fname_case")
358   au BufNewFile,BufRead *.C,*.H setf cpp
359 endif
361 " .h files can be C, Ch C++, ObjC or ObjC++.
362 " Set c_syntax_for_h if you want C, ch_syntax_for_h if you want Ch. ObjC is
363 " detected automatically.
364 au BufNewFile,BufRead *.h                       call s:FTheader()
366 func! s:FTheader()
367   if match(getline(1, min([line("$"), 200])), '^@\(interface\|end\|class\)') > -1
368     setf objc
369   elseif exists("g:c_syntax_for_h")
370     setf c
371   elseif exists("g:ch_syntax_for_h")
372     setf ch
373   else
374     setf cpp
375   endif
376 endfunc
378 " Ch (CHscript)
379 au BufNewFile,BufRead *.chf                     setf ch
381 " TLH files are C++ headers generated by Visual C++'s #import from typelibs
382 au BufNewFile,BufRead *.tlh                     setf cpp
384 " Cascading Style Sheets
385 au BufNewFile,BufRead *.css                     setf css
387 " Century Term Command Scripts (*.cmd too)
388 au BufNewFile,BufRead *.con                     setf cterm
390 " Changelog
391 au BufNewFile,BufRead changelog.Debian,changelog.dch,NEWS.Debian,NEWS.dch
392                                         \       setf debchangelog
394 au BufNewFile,BufRead [cC]hange[lL]og
395         \  if getline(1) =~ '; urgency='
396         \|   setf debchangelog
397         \| else
398         \|   setf changelog
399         \| endif
401 au BufNewFile,BufRead NEWS
402         \  if getline(1) =~ '; urgency='
403         \|   setf debchangelog
404         \| endif
406 " CHILL
407 au BufNewFile,BufRead *..ch                     setf chill
409 " Changes for WEB and CWEB or CHILL
410 au BufNewFile,BufRead *.ch                      call s:FTchange()
412 " This function checks if one of the first ten lines start with a '@'.  In
413 " that case it is probably a change file.
414 " If the first line starts with # or ! it's probably a ch file.
415 " If a line has "main", "include", "//" ir "/*" it's probably ch.
416 " Otherwise CHILL is assumed.
417 func! s:FTchange()
418   let lnum = 1
419   while lnum <= 10
420     if getline(lnum)[0] == '@'
421       setf change
422       return
423     endif
424     if lnum == 1 && (getline(1)[0] == '#' || getline(1)[0] == '!')
425       setf ch
426       return
427     endif
428     if getline(lnum) =~ "MODULE"
429       setf chill
430       return
431     endif
432     if getline(lnum) =~ 'main\s*(\|#\s*include\|//'
433       setf ch
434       return
435     endif
436     let lnum = lnum + 1
437   endwhile
438   setf chill
439 endfunc
441 " ChordPro
442 au BufNewFile,BufRead *.chopro,*.crd,*.cho,*.crdpro,*.chordpro  setf chordpro
444 " Clean
445 au BufNewFile,BufRead *.dcl,*.icl               setf clean
447 " Clever
448 au BufNewFile,BufRead *.eni                     setf cl
450 " Clever or dtd
451 au BufNewFile,BufRead *.ent                     call s:FTent()
453 func! s:FTent()
454   " This function checks for valid cl syntax in the first five lines.
455   " Look for either an opening comment, '#', or a block start, '{".
456   " If not found, assume SGML.
457   let lnum = 1
458   while lnum < 6
459     let line = getline(lnum)
460     if line =~ '^\s*[#{]'
461       setf cl
462       return
463     elseif line !~ '^\s*$'
464       " Not a blank line, not a comment, and not a block start,
465       " so doesn't look like valid cl code.
466       break
467     endif
468     let lnum = lnum + 1
469   endw
470   setf dtd
471 endfunc
473 " Clipper (or FoxPro; could also be eviews)
474 au BufNewFile,BufRead *.prg
475         \ if exists("g:filetype_prg") |
476         \   exe "setf " . g:filetype_prg |
477         \ else |
478         \   setf clipper |
479         \ endif
481 " Cmake
482 au BufNewFile,BufRead CMakeLists.txt,*.cmake,*.cmake.in         setf cmake
484 " Cmusrc
485 au BufNewFile,BufRead ~/.cmus/{autosave,rc,command-history,*.theme} setf cmusrc
486 au BufNewFile,BufRead */cmus/{rc,*.theme}                       setf cmusrc
488 " Cobol
489 au BufNewFile,BufRead *.cbl,*.cob,*.lib setf cobol
490 "   cobol or zope form controller python script? (heuristic)
491 au BufNewFile,BufRead *.cpy
492         \ if getline(1) =~ '^##' |
493         \   setf python |
494         \ else |
495         \   setf cobol |
496         \ endif
498 " Coco/R
499 au BufNewFile,BufRead *.atg                     setf coco
501 " Cold Fusion
502 au BufNewFile,BufRead *.cfm,*.cfi,*.cfc         setf cf
504 " Configure scripts
505 au BufNewFile,BufRead configure.in,configure.ac setf config
507 " CUDA  Cumpute Unified Device Architecture
508 au BufNewFile,BufRead *.cu                      setf cuda
510 " WildPackets EtherPeek Decoder
511 au BufNewFile,BufRead *.dcd                     setf dcd
513 " Enlightenment configuration files
514 au BufNewFile,BufRead *enlightenment/*.cfg      setf c
516 " Eterm
517 au BufNewFile,BufRead *Eterm/*.cfg              setf eterm
519 " Lynx config files
520 au BufNewFile,BufRead lynx.cfg                  setf lynx
522 " Quake
523 au BufNewFile,BufRead *baseq[2-3]/*.cfg,*id1/*.cfg      setf quake
524 au BufNewFile,BufRead *quake[1-3]/*.cfg                 setf quake
526 " Quake C
527 au BufNewFile,BufRead *.qc                      setf c
529 " Configure files
530 au BufNewFile,BufRead *.cfg                     setf cfg
532 " Communicating Sequential Processes
533 au BufNewFile,BufRead *.csp,*.fdr               setf csp
535 " CUPL logic description and simulation
536 au BufNewFile,BufRead *.pld                     setf cupl
537 au BufNewFile,BufRead *.si                      setf cuplsim
539 " Debian Control
540 au BufNewFile,BufRead */debian/control          setf debcontrol
541 au BufNewFile,BufRead control
542         \  if getline(1) =~ '^Source:'
543         \|   setf debcontrol
544         \| endif
546 " Debian Sources.list
547 au BufNewFile,BufRead /etc/apt/sources.list     setf debsources
549 " Deny hosts
550 au BufNewFile,BufRead denyhosts.conf            setf denyhosts
552 " ROCKLinux package description
553 au BufNewFile,BufRead *.desc                    setf desc
555 " the D language or dtrace
556 au BufNewFile,BufRead *.d                       call s:DtraceCheck()
558 func! s:DtraceCheck()
559   let lines = getline(1, min([line("$"), 100]))
560   if match(lines, '^#!\S\+dtrace\|#pragma\s\+D\s\+option\|:\S\{-}:\S\{-}:') > -1
561     setf dtrace
562   else
563     setf d
564   endif
565 endfunc
567 " Desktop files
568 au BufNewFile,BufRead *.desktop,.directory      setf desktop
570 " Dict config
571 au BufNewFile,BufRead dict.conf,.dictrc         setf dictconf
573 " Dictd config
574 au BufNewFile,BufRead dictd.conf                setf dictdconf
576 " Diff files
577 au BufNewFile,BufRead *.diff,*.rej,*.patch      setf diff
579 " Dircolors
580 au BufNewFile,BufRead .dir_colors,/etc/DIR_COLORS       setf dircolors
582 " Diva (with Skill) or InstallShield
583 au BufNewFile,BufRead *.rul
584         \ if getline(1).getline(2).getline(3).getline(4).getline(5).getline(6) =~? 'InstallShield' |
585         \   setf ishd |
586         \ else |
587         \   setf diva |
588         \ endif
590 " DCL (Digital Command Language - vms) or DNS zone file
591 au BufNewFile,BufRead *.com                     call s:BindzoneCheck('dcl')
593 " DOT
594 au BufNewFile,BufRead *.dot                     setf dot
596 " Dylan - lid files
597 au BufNewFile,BufRead *.lid                     setf dylanlid
599 " Dylan - intr files (melange)
600 au BufNewFile,BufRead *.intr                    setf dylanintr
602 " Dylan
603 au BufNewFile,BufRead *.dylan                   setf dylan
605 " Microsoft Module Definition
606 au BufNewFile,BufRead *.def                     setf def
608 " Dracula
609 au BufNewFile,BufRead *.drac,*.drc,*lvs,*lpe    setf dracula
611 " dsl
612 au BufNewFile,BufRead *.dsl                     setf dsl
614 " DTD (Document Type Definition for XML)
615 au BufNewFile,BufRead *.dtd                     setf dtd
617 " EDIF (*.edf,*.edif,*.edn,*.edo)
618 au BufNewFile,BufRead *.ed\(f\|if\|n\|o\)       setf edif
620 " Embedix Component Description
621 au BufNewFile,BufRead *.ecd                     setf ecd
623 " Eiffel or Specman
624 au BufNewFile,BufRead *.e,*.E                   call s:FTe()
626 " Elinks configuration
627 au BufNewFile,BufRead */etc/elinks.conf,*/.elinks/elinks.conf   setf elinks
629 func! s:FTe()
630   let n = 1
631   while n < 100 && n < line("$")
632     if getline(n) =~ "^\\s*\\(<'\\|'>\\)\\s*$"
633       setf specman
634       return
635     endif
636     let n = n + 1
637   endwhile
638   setf eiffel
639 endfunc
641 " ERicsson LANGuage; Yaws is erlang too
642 au BufNewFile,BufRead *.erl,*.hrl,*.yaws        setf erlang
644 " Elm Filter Rules file
645 au BufNewFile,BufRead filter-rules              setf elmfilt
647 " ESMTP rc file
648 au BufNewFile,BufRead *esmtprc                  setf esmtprc
650 " ESQL-C
651 au BufNewFile,BufRead *.ec,*.EC                 setf esqlc
653 " Esterel
654 au BufNewFile,BufRead *.strl                    setf esterel
656 " Essbase script
657 au BufNewFile,BufRead *.csc                     setf csc
659 " Exim
660 au BufNewFile,BufRead exim.conf                 setf exim
662 " Expect
663 au BufNewFile,BufRead *.exp                     setf expect
665 " Exports
666 au BufNewFile,BufRead exports                   setf exports
668 " Factor
669 au BufNewFile,BufRead *.factor                  setf factor
671 " Fetchmail RC file
672 au BufNewFile,BufRead .fetchmailrc              setf fetchmail
674 " FlexWiki
675 au BufNewFile,BufRead *.wiki                    setf flexwiki
677 " Focus Executable
678 au BufNewFile,BufRead *.fex,*.focexec           setf focexec
680 " Focus Master file (but not for auto.master)
681 au BufNewFile,BufRead auto.master               setf conf
682 au BufNewFile,BufRead *.mas,*.master            setf master
684 " Forth
685 au BufNewFile,BufRead *.fs,*.ft                 setf forth
687 " Reva Forth
688 au BufNewFile,BufRead *.frt                     setf reva
690 " Fortran
691 if has("fname_case")
692   au BufNewFile,BufRead *.F,*.FOR,*.FPP,*.FTN,*.F77,*.F90,*.F95  setf fortran
693 endif
694 au BufNewFile,BufRead   *.f,*.for,*.fortran,*.fpp,*.ftn,*.f77,*.f90,*.f95  setf fortran
696 " Framescript
697 au BufNewFile,BufRead *.fsl                     setf framescript
699 " FStab
700 au BufNewFile,BufRead fstab,mtab                setf fstab
702 " GDB command files
703 au BufNewFile,BufRead .gdbinit                  setf gdb
705 " GDMO
706 au BufNewFile,BufRead *.mo,*.gdmo               setf gdmo
708 " Gedcom
709 au BufNewFile,BufRead *.ged                     setf gedcom
711 " Git
712 autocmd BufNewFile,BufRead *.git/COMMIT_EDITMSG    setf gitcommit
713 autocmd BufNewFile,BufRead *.git/config,.gitconfig setf gitconfig
714 autocmd BufNewFile,BufRead git-rebase-todo         setf gitrebase
715 autocmd BufNewFile,BufRead .msg.[0-9]*
716       \ if getline(1) =~ '^From.*# This line is ignored.$' |
717       \   setf gitsendemail |
718       \ endif
719 autocmd BufNewFile,BufRead *.git/**
720       \ if getline(1) =~ '^\x\{40\}\>\|^ref: ' |
721       \   setf git |
722       \ endif
724 " Gkrellmrc
725 au BufNewFile,BufRead gkrellmrc,gkrellmrc_?     setf gkrellmrc
727 " GP scripts (2.0 and onward)
728 au BufNewFile,BufRead *.gp,.gprc                setf gp
730 " GPG
731 au BufNewFile,BufRead */.gnupg/options          setf gpg
732 au BufNewFile,BufRead */.gnupg/gpg.conf         setf gpg
733 au BufNewFile,BufRead /usr/**/gnupg/options.skel setf gpg
735 " Gnuplot scripts
736 au BufNewFile,BufRead *.gpi                     setf gnuplot
738 " GrADS scripts
739 au BufNewFile,BufRead *.gs                      setf grads
741 " Gretl
742 au BufNewFile,BufRead *.gretl                   setf gretl
744 " Groovy
745 au BufNewFile,BufRead *.groovy                  setf groovy
747 " GNU Server Pages
748 au BufNewFile,BufRead *.gsp                     setf gsp
750 " Group file
751 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
753 " GTK RC
754 au BufNewFile,BufRead .gtkrc,gtkrc              setf gtkrc
756 " Haml
757 au BufNewFile,BufRead *.haml                    setf haml
759 " Hamster Classic | Playground files
760 au BufNewFile,BufRead *.hsc,*.hsm               setf hamster
762 " Haskell
763 au BufNewFile,BufRead *.hs                      setf haskell
764 au BufNewFile,BufRead *.lhs                     setf lhaskell
765 au BufNewFile,BufRead *.chs                     setf chaskell
767 " Haste
768 au BufNewFile,BufRead *.ht                      setf haste
769 au BufNewFile,BufRead *.htpp                    setf hastepreproc
771 " Hercules
772 au BufNewFile,BufRead *.vc,*.ev,*.rs,*.sum,*.errsum     setf hercules
774 " HEX (Intel)
775 au BufNewFile,BufRead *.hex,*.h32               setf hex
777 " Tilde (must be before HTML)
778 au BufNewFile,BufRead *.t.html                  setf tilde
780 " HTML (.shtml and .stm for server side)
781 au BufNewFile,BufRead *.html,*.htm,*.shtml,*.stm  call s:FThtml()
783 " Distinguish between HTML, XHTML and Django
784 func! s:FThtml()
785   let n = 1
786   while n < 10 && n < line("$")
787     if getline(n) =~ '\<DTD\s\+XHTML\s'
788       setf xhtml
789       return
790     endif
791     if getline(n) =~ '{%\s*\(extends\|block\)\>'
792       setf htmldjango
793       return
794     endif
795     let n = n + 1
796   endwhile
797   setf html
798 endfunc
800 " HTML with Ruby - eRuby
801 au BufNewFile,BufRead *.erb,*.rhtml             setf eruby
803 " HTML with M4
804 au BufNewFile,BufRead *.html.m4                 setf htmlm4
806 " HTML Cheetah template
807 au BufNewFile,BufRead *.tmpl                    setf htmlcheetah
809 " Host config
810 au BufNewFile,BufRead /etc/host.conf            setf hostconf
812 " Hosts access
813 au BufNewFile,BufRead /etc/hosts.allow,/etc/hosts.deny  setf hostsaccess
815 " Hyper Builder
816 au BufNewFile,BufRead *.hb                      setf hb
818 " Icon
819 au BufNewFile,BufRead *.icn                     setf icon
821 " IDL (Interface Description Language)
822 au BufNewFile,BufRead *.idl                     call s:FTidl()
824 " Distinguish between standard IDL and MS-IDL
825 func! s:FTidl()
826   let n = 1
827   while n < 50 && n < line("$")
828     if getline(n) =~ '^\s*import\s\+"\(unknwn\|objidl\)\.idl"'
829       setf msidl
830       return
831     endif
832     let n = n + 1
833   endwhile
834   setf idl
835 endfunc
837 " Microsoft IDL (Interface Description Language)  Also *.idl
838 " MOF = WMI (Windows Management Instrumentation) Managed Object Format
839 au BufNewFile,BufRead *.odl,*.mof               setf msidl
841 " Icewm menu
842 au BufNewFile,BufRead */.icewm/menu             setf icemenu
844 " Indent profile (must come before IDL *.pro!)
845 au BufNewFile,BufRead .indent.pro               setf indent
846 au BufNewFile,BufRead indent.pro                call s:ProtoCheck('indent')
848 " IDL (Interactive Data Language)
849 au BufNewFile,BufRead *.pro                     call s:ProtoCheck('idlang')
851 " Distinguish between "default" and Cproto prototype file. */
852 func! s:ProtoCheck(default)
853   " Cproto files have a comment in the first line and a function prototype in
854   " the second line, it always ends in ";".  Indent files may also have
855   " comments, thus we can't match comments to see the difference.
856   if getline(2) =~ ';$'
857     setf cpp
858   else
859     exe 'setf ' . a:default
860   endif
861 endfunc
864 " Indent RC
865 au BufNewFile,BufRead indentrc                  setf indent
867 " Inform
868 au BufNewFile,BufRead *.inf,*.INF               setf inform
870 " Initng
871 au BufNewFile,BufRead /etc/initng/**/*.i,*.ii   setf initng
873 " Ipfilter
874 au BufNewFile,BufRead ipf.conf,ipf6.conf,ipf.rules      setf ipfilter
876 " Informix 4GL (source - canonical, include file, I4GL+M4 preproc.)
877 au BufNewFile,BufRead *.4gl,*.4gh,*.m4gl        setf fgl
879 " .INI file for MSDOS
880 au BufNewFile,BufRead *.ini                     setf dosini
882 " SysV Inittab
883 au BufNewFile,BufRead inittab                   setf inittab
885 " Inno Setup
886 au BufNewFile,BufRead *.iss                     setf iss
888 " JAL
889 au BufNewFile,BufRead *.jal,*.JAL               setf jal
891 " Jam
892 au BufNewFile,BufRead *.jpl,*.jpr               setf jam
894 " Java
895 au BufNewFile,BufRead *.java,*.jav              setf java
897 " JavaCC
898 au BufNewFile,BufRead *.jj,*.jjt                setf javacc
900 " JavaScript, ECMAScript
901 au BufNewFile,BufRead *.js,*.javascript,*.es    setf javascript
903 " Java Server Pages
904 au BufNewFile,BufRead *.jsp                     setf jsp
906 " Java Properties resource file (note: doesn't catch font.properties.pl)
907 au BufNewFile,BufRead *.properties,*.properties_??,*.properties_??_??   setf jproperties
908 au BufNewFile,BufRead *.properties_??_??_*      call s:StarSetf('jproperties')
910 " Jess
911 au BufNewFile,BufRead *.clp                     setf jess
913 " Jgraph
914 au BufNewFile,BufRead *.jgr                     setf jgraph
916 " Kixtart
917 au BufNewFile,BufRead *.kix                     setf kix
919 " Kimwitu[++]
920 au BufNewFile,BufRead *.k                       setf kwt
922 " KDE script
923 au BufNewFile,BufRead *.ks                      setf kscript
925 " Kconfig
926 au BufNewFile,BufRead Kconfig,Kconfig.debug     setf kconfig
928 " Lace (ISE)
929 au BufNewFile,BufRead *.ace,*.ACE               setf lace
931 " Latte
932 au BufNewFile,BufRead *.latte,*.lte             setf latte
934 " Limits
935 au BufNewFile,BufRead /etc/limits               setf limits
937 " LambdaProlog (*.mod too, see Modsim)
938 au BufNewFile,BufRead *.sig                     setf lprolog
940 " LDAP LDIF
941 au BufNewFile,BufRead *.ldif                    setf ldif
943 " Ld loader
944 au BufNewFile,BufRead *.ld                      setf ld
946 " Lex
947 au BufNewFile,BufRead *.lex,*.l                 setf lex
949 " Libao
950 au BufNewFile,BufRead /etc/libao.conf,*/.libao  setf libao
952 " Libsensors
953 au BufNewFile,BufRead /etc/sensors.conf         setf sensors
955 " LFTP
956 au BufNewFile,BufRead lftp.conf,.lftprc,*lftp/rc        setf lftp
958 " Lifelines (or Lex for C++!)
959 au BufNewFile,BufRead *.ll                      setf lifelines
961 " Lilo: Linux loader
962 au BufNewFile,BufRead lilo.conf*                call s:StarSetf('lilo')
964 " Lisp (*.el = ELisp, *.cl = Common Lisp, *.jl = librep Lisp)
965 if has("fname_case")
966   au BufNewFile,BufRead *.lsp,*.lisp,*.el,*.cl,*.jl,*.L,.emacs,.sawfishrc setf lisp
967 else
968   au BufNewFile,BufRead *.lsp,*.lisp,*.el,*.cl,*.jl,.emacs,.sawfishrc setf lisp
969 endif
971 " SBCL implementation of Common Lisp
972 au BufNewFile,BufRead sbclrc,.sbclrc            setf lisp
974 " Lite
975 au BufNewFile,BufRead *.lite,*.lt               setf lite
977 " LiteStep RC files
978 au BufNewFile,BufRead */LiteStep/*/*.rc         setf litestep
980 " Login access
981 au BufNewFile,BufRead /etc/login.access         setf loginaccess
983 " Login defs
984 au BufNewFile,BufRead /etc/login.defs           setf logindefs
986 " Logtalk
987 au BufNewFile,BufRead *.lgt                     setf logtalk
989 " LOTOS
990 au BufNewFile,BufRead *.lot,*.lotos             setf lotos
992 " Lout (also: *.lt)
993 au BufNewFile,BufRead *.lou,*.lout              setf lout
995 " Lua
996 au BufNewFile,BufRead *.lua                     setf lua
998 " Linden Scripting Language (Second Life)
999 au BufNewFile,BufRead *.lsl                     setf lsl
1001 " Lynx style file (or LotusScript!)
1002 au BufNewFile,BufRead *.lss                     setf lss
1004 " M4
1005 au BufNewFile,BufRead *.m4
1006         \ if expand("<afile>") !~? 'html.m4$\|fvwm2rc' | setf m4 | endif
1008 " MaGic Point
1009 au BufNewFile,BufRead *.mgp                     setf mgp
1011 " Mail (for Elm, trn, mutt, muttng, rn, slrn)
1012 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
1014 " Mail aliases
1015 au BufNewFile,BufRead /etc/mail/aliases,/etc/aliases    setf mailaliases
1017 " Mailcap configuration file
1018 au BufNewFile,BufRead .mailcap,mailcap          setf mailcap
1020 " Makefile
1021 au BufNewFile,BufRead *[mM]akefile,*.mk,*.mak,*.dsp setf make
1023 " MakeIndex
1024 au BufNewFile,BufRead *.ist,*.mst               setf ist
1026 " Manpage
1027 au BufNewFile,BufRead *.man                     setf man
1029 " Man config
1030 au BufNewFile,BufRead /etc/man.conf,man.config  setf manconf
1032 " Maple V
1033 au BufNewFile,BufRead *.mv,*.mpl,*.mws          setf maple
1035 " Map (UMN mapserver config file)
1036 au BufNewFile,BufRead *.map                     setf map
1038 " Mason
1039 au BufNewFile,BufRead *.mason,*.mhtml           setf mason
1041 " Matlab or Objective C
1042 au BufNewFile,BufRead *.m                       call s:FTm()
1044 func! s:FTm()
1045   let n = 1
1046   while n < 10
1047     let line = getline(n)
1048     if line =~ '^\s*\(#\s*\(include\|import\)\>\|/\*\)'
1049       setf objc
1050       return
1051     endif
1052     if line =~ '^\s*%'
1053       setf matlab
1054       return
1055     endif
1056     if line =~ '^\s*(\*'
1057       setf mma
1058       return
1059     endif
1060     let n = n + 1
1061   endwhile
1062   if exists("g:filetype_m")
1063     exe "setf " . g:filetype_m
1064   else
1065     setf matlab
1066   endif
1067 endfunc
1069 " Mathematica notebook
1070 au BufNewFile,BufRead *.nb                      setf mma
1072 " Maya Extension Language
1073 au BufNewFile,BufRead *.mel                     setf mel
1075 " Messages
1076 au BufNewFile,BufRead /var/log/messages,/var/log/messages.*[0-9]  setf messages
1078 " Metafont
1079 au BufNewFile,BufRead *.mf                      setf mf
1081 " MetaPost
1082 au BufNewFile,BufRead *.mp                      setf mp
1084 " MGL
1085 au BufNewFile,BufRead *.mgl                     setf mgl
1087 " MMIX or VMS makefile
1088 au BufNewFile,BufRead *.mms                     call s:FTmms()
1090 " Symbian meta-makefile definition (MMP)
1091 au BufNewFile,BufRead *.mmp                     setf mmp
1093 func! s:FTmms()
1094   let n = 1
1095   while n < 10
1096     let line = getline(n)
1097     if line =~ '^\s*\(%\|//\)' || line =~ '^\*'
1098       setf mmix
1099       return
1100     endif
1101     if line =~ '^\s*#'
1102       setf make
1103       return
1104     endif
1105     let n = n + 1
1106   endwhile
1107   setf mmix
1108 endfunc
1111 " Modsim III (or LambdaProlog)
1112 au BufNewFile,BufRead *.mod
1113         \ if getline(1) =~ '\<module\>' |
1114         \   setf lprolog |
1115         \ else |
1116         \   setf modsim3 |
1117         \ endif
1119 " Modula 2
1120 au BufNewFile,BufRead *.m2,*.DEF,*.MOD,*.md,*.mi setf modula2
1122 " Modula 3 (.m3, .i3, .mg, .ig)
1123 au BufNewFile,BufRead *.[mi][3g]                setf modula3
1125 " Monk
1126 au BufNewFile,BufRead *.isc,*.monk,*.ssc,*.tsc  setf monk
1128 " MOO
1129 au BufNewFile,BufRead *.moo                     setf moo
1131 " Modconf
1132 au BufNewFile,BufRead /etc/modules.conf,/etc/conf.modules       setf modconf
1133 au BufNewFile,BufRead /etc/modutils/*
1134         \ if executable(expand("<afile>")) != 1
1135         \|  call s:StarSetf('modconf')
1136         \|endif
1138 " Mplayer config
1139 au BufNewFile,BufRead mplayer.conf,*/.mplayer/config    setf mplayerconf
1141 " Moterola S record
1142 au BufNewFile,BufRead *.s19,*.s28,*.s37         setf srec
1144 " Mrxvtrc
1145 au BufNewFile,BufRead mrxvtrc,.mrxvtrc          setf mrxvtrc
1147 " Msql
1148 au BufNewFile,BufRead *.msql                    setf msql
1150 " Mysql
1151 au BufNewFile,BufRead *.mysql                   setf mysql
1153 " M$ Resource files
1154 au BufNewFile,BufRead *.rc                      setf rc
1156 " MuPAD source
1157 au BufRead,BufNewFile *.mu                      setf mupad
1159 " Mush
1160 au BufNewFile,BufRead *.mush                    setf mush
1162 " Mutt setup file (also for Muttng)
1163 au BufNewFile,BufRead Mutt{ng,}rc               setf muttrc
1165 " Nano
1166 au BufNewFile,BufRead /etc/nanorc,.nanorc       setf nanorc
1168 " Nastran input/DMAP
1169 "au BufNewFile,BufRead *.dat                    setf nastran
1171 " Natural
1172 au BufNewFile,BufRead *.NS[ACGLMNPS]            setf natural
1174 " Netrc
1175 au BufNewFile,BufRead .netrc                    setf netrc
1177 " Novell netware batch files
1178 au BufNewFile,BufRead *.ncf                     setf ncf
1180 " Nroff/Troff (*.ms and *.t are checked below)
1181 au BufNewFile,BufRead *.me
1182         \ if expand("<afile>") != "read.me" && expand("<afile>") != "click.me" |
1183         \   setf nroff |
1184         \ endif
1185 au BufNewFile,BufRead *.tr,*.nr,*.roff,*.tmac,*.mom     setf nroff
1186 au BufNewFile,BufRead *.[1-9]                   call s:FTnroff()
1188 " This function checks if one of the first five lines start with a dot.  In
1189 " that case it is probably an nroff file: 'filetype' is set and 1 is returned.
1190 func! s:FTnroff()
1191   if getline(1)[0] . getline(2)[0] . getline(3)[0] . getline(4)[0] . getline(5)[0] =~ '\.'
1192     setf nroff
1193     return 1
1194   endif
1195   return 0
1196 endfunc
1198 " Nroff or Objective C++
1199 au BufNewFile,BufRead *.mm                      call s:FTmm()
1201 func! s:FTmm()
1202   let n = 1
1203   while n < 10
1204     let line = getline(n)
1205     if line =~ '^\s*\(#\s*\(include\|import\)\>\|/\*\)'
1206       setf objcpp
1207       return
1208     endif
1209     let n = n + 1
1210   endwhile
1211   setf nroff
1212 endfunc
1214 " Not Quite C
1215 au BufNewFile,BufRead *.nqc                     setf nqc
1217 " NSIS
1218 au BufNewFile,BufRead *.nsi                     setf nsis
1220 " OCAML
1221 au BufNewFile,BufRead *.ml,*.mli,*.mll,*.mly    setf ocaml
1223 " Occam
1224 au BufNewFile,BufRead *.occ                     setf occam
1226 " Omnimark
1227 au BufNewFile,BufRead *.xom,*.xin               setf omnimark
1229 " OpenROAD
1230 au BufNewFile,BufRead *.or                      setf openroad
1232 " OPL
1233 au BufNewFile,BufRead *.[Oo][Pp][Ll]            setf opl
1235 " Oracle config file
1236 au BufNewFile,BufRead *.ora                     setf ora
1238 " Packet filter conf
1239 au BufNewFile,BufRead pf.conf                   setf pf
1241 " Pam conf
1242 au BufNewFile,BufRead /etc/pam.conf             setf pamconf
1244 " PApp
1245 au BufNewFile,BufRead *.papp,*.pxml,*.pxsl      setf papp
1247 " Password file
1248 au BufNewFile,BufRead /etc/passwd,/etc/passwd-,/etc/passwd.edit,/etc/shadow,/etc/shadow-,/var/backups/passwd.bak,/var/backups/shadow.bak setf passwd
1250 " Pascal (also *.p)
1251 au BufNewFile,BufRead *.pas                     setf pascal
1253 " Delphi project file
1254 au BufNewFile,BufRead *.dpr                     setf pascal
1256 " PDF
1257 au BufNewFile,BufRead *.pdf                     setf pdf
1259 " Perl
1260 if has("fname_case")
1261   au BufNewFile,BufRead *.pl,*.PL               call s:FTpl()
1262 else
1263   au BufNewFile,BufRead *.pl                    call s:FTpl()
1264 endif
1265 au BufNewFile,BufRead *.plx,*.al                setf perl
1267 func! s:FTpl()
1268   if exists("g:filetype_pl")
1269     exe "setf " . g:filetype_pl
1270   else
1271     " recognize Prolog by specific text in the first non-empty line
1272     " require a blank after the '%' because Perl uses "%list" and "%translate"
1273     let l = getline(nextnonblank(1))
1274     if l =~ '\<prolog\>' || l =~ '^\s*\(%\+\(\s\|$\)\|/\*\)' || l =~ ':-'
1275       setf prolog
1276     else
1277       setf perl
1278     endif
1279   endif
1280 endfunc
1282 " Perl, XPM or XPM2
1283 au BufNewFile,BufRead *.pm
1284         \ if getline(1) =~ "XPM2" |
1285         \   setf xpm2 |
1286         \ elseif getline(1) =~ "XPM" |
1287         \   setf xpm |
1288         \ else |
1289         \   setf perl |
1290         \ endif
1292 " Perl POD
1293 au BufNewFile,BufRead *.pod                     setf pod
1295 " Php, php3, php4, etc.
1296 " Also Phtml (was used for PHP 2 in the past)
1297 " Also .ctp for Cake template file
1298 au BufNewFile,BufRead *.php,*.php\d,*.phtml,*.ctp       setf php
1300 " Pike
1301 au BufNewFile,BufRead *.pike,*.lpc,*.ulpc,*.pmod setf pike
1303 " Pinfo config
1304 au BufNewFile,BufRead */etc/pinforc,*/.pinforc  setf pinfo
1306 " Palm Resource compiler
1307 au BufNewFile,BufRead *.rcp                     setf pilrc
1309 " Pine config
1310 au BufNewFile,BufRead .pinerc,pinerc,.pinercex,pinercex         setf pine
1312 " PL/M (also: *.inp)
1313 au BufNewFile,BufRead *.plm,*.p36,*.pac         setf plm
1315 " PL/SQL
1316 au BufNewFile,BufRead *.pls,*.plsql             setf plsql
1318 " PLP
1319 au BufNewFile,BufRead *.plp                     setf plp
1321 " PO and PO template (GNU gettext)
1322 au BufNewFile,BufRead *.po,*.pot                setf po
1324 " Postfix main config
1325 au BufNewFile,BufRead main.cf                   setf pfmain
1327 " PostScript (+ font files, encapsulated PostScript, Adobe Illustrator)
1328 au BufNewFile,BufRead *.ps,*.pfa,*.afm,*.eps,*.epsf,*.epsi,*.ai   setf postscr
1330 " PostScript Printer Description
1331 au BufNewFile,BufRead *.ppd                     setf ppd
1333 " Povray
1334 au BufNewFile,BufRead *.pov                     setf pov
1336 " Povray configuration
1337 au BufNewFile,BufRead .povrayrc                 setf povini
1339 " Povray, PHP or assembly
1340 au BufNewFile,BufRead *.inc                     call s:FTinc()
1342 func! s:FTinc()
1343   if exists("g:filetype_inc")
1344     exe "setf " . g:filetype_inc
1345   else
1346     let lines = getline(1).getline(2).getline(3)
1347     if lines =~? "perlscript"
1348       setf aspperl
1349     elseif lines =~ "<%"
1350       setf aspvbs
1351     elseif lines =~ "<?"
1352       setf php
1353     else
1354       call s:FTasmsyntax()
1355       if exists("b:asmsyntax")
1356         exe "setf " . fnameescape(b:asmsyntax)
1357       else
1358         setf pov
1359       endif
1360     endif
1361   endif
1362 endfunc
1364 " Printcap and Termcap
1365 au BufNewFile,BufRead *printcap
1366         \ let b:ptcap_type = "print" | setf ptcap
1367 au BufNewFile,BufRead *termcap
1368         \ let b:ptcap_type = "term" | setf ptcap
1370 " PCCTS / ANTRL
1371 "au BufNewFile,BufRead *.g                      setf antrl
1372 au BufNewFile,BufRead *.g                       setf pccts
1374 " PPWizard
1375 au BufNewFile,BufRead *.it,*.ih                 setf ppwiz
1377 " Oracle Pro*C/C++
1378 au BufNewFile,BufRead *.pc                      setf proc
1380 " Privoxy actions file
1381 au BufNewFile,BufRead *.action                  setf privoxy
1383 " Procmail
1384 au BufNewFile,BufRead .procmail,.procmailrc     setf procmail
1386 " Progress or CWEB
1387 au BufNewFile,BufRead *.w                       call s:FTprogress_cweb()
1389 func! s:FTprogress_cweb()
1390   if exists("g:filetype_w")
1391     exe "setf " . g:filetype_w
1392     return
1393   endif
1394   if getline(1) =~ '&ANALYZE' || getline(3) =~ '&GLOBAL-DEFINE'
1395     setf progress
1396   else
1397     setf cweb
1398   endif
1399 endfunc
1401 " Progress or assembly
1402 au BufNewFile,BufRead *.i                       call s:FTprogress_asm()
1404 func! s:FTprogress_asm()
1405   if exists("g:filetype_i")
1406     exe "setf " . g:filetype_i
1407     return
1408   endif
1409   " This function checks for an assembly comment the first ten lines.
1410   " If not found, assume Progress.
1411   let lnum = 1
1412   while lnum <= 10 && lnum < line('$')
1413     let line = getline(lnum)
1414     if line =~ '^\s*;' || line =~ '^\*'
1415       call s:FTasm()
1416       return
1417     elseif line !~ '^\s*$' || line =~ '^/\*'
1418       " Not an empty line: Doesn't look like valid assembly code.
1419       " Or it looks like a Progress /* comment
1420       break
1421     endif
1422     let lnum = lnum + 1
1423   endw
1424   setf progress
1425 endfunc
1427 " Progress or Pascal
1428 au BufNewFile,BufRead *.p                       call s:FTprogress_pascal()
1430 func! s:FTprogress_pascal()
1431   if exists("g:filetype_p")
1432     exe "setf " . g:filetype_p
1433     return
1434   endif
1435   " This function checks for valid Pascal syntax in the first ten lines.
1436   " Look for either an opening comment or a program start.
1437   " If not found, assume Progress.
1438   let lnum = 1
1439   while lnum <= 10 && lnum < line('$')
1440     let line = getline(lnum)
1441     if line =~ '^\s*\(program\|unit\|procedure\|function\|const\|type\|var\)\>'
1442         \ || line =~ '^\s*{' || line =~ '^\s*(\*'
1443       setf pascal
1444       return
1445     elseif line !~ '^\s*$' || line =~ '^/\*'
1446       " Not an empty line: Doesn't look like valid Pascal code.
1447       " Or it looks like a Progress /* comment
1448       break
1449     endif
1450     let lnum = lnum + 1
1451   endw
1452   setf progress
1453 endfunc
1456 " Software Distributor Product Specification File (POSIX 1387.2-1995)
1457 au BufNewFile,BufRead *.psf                     setf psf
1458 au BufNewFile,BufRead INDEX,INFO
1459         \ if getline(1) =~ '^\s*\(distribution\|installed_software\|root\|bundle\|product\)\s*$' |
1460         \   setf psf |
1461         \ endif
1463 " Prolog
1464 au BufNewFile,BufRead *.pdb                     setf prolog
1466 " Promela
1467 au BufNewFile,BufRead *.pml                     setf promela
1469 " Protocols
1470 au BufNewFile,BufRead /etc/protocols            setf protocols
1472 " Pyrex
1473 au BufNewFile,BufRead *.pyx,*.pxd               setf pyrex
1475 " Python
1476 au BufNewFile,BufRead *.py,*.pyw                setf python
1478 " Quixote (Python-based web framework)
1479 au BufNewFile,BufRead *.ptl                     setf python
1481 " Radiance
1482 au BufNewFile,BufRead *.rad,*.mat               setf radiance
1484 " Ratpoison config/command files
1485 au BufNewFile,BufRead .ratpoisonrc,ratpoisonrc  setf ratpoison
1487 " RCS file
1488 au BufNewFile,BufRead *\,v                      setf rcs
1490 " Readline
1491 au BufNewFile,BufRead .inputrc,inputrc          setf readline
1493 " Registry for MS-Windows
1494 au BufNewFile,BufRead *.reg
1495         \ if getline(1) =~? '^REGEDIT[0-9]*\s*$\|^Windows Registry Editor Version \d*\.\d*\s*$' | setf registry | endif
1497 " Renderman Interface Bytestream
1498 au BufNewFile,BufRead *.rib                     setf rib
1500 " Rexx
1501 au BufNewFile,BufRead *.rexx,*.rex,*.jrexx,*.rxj,*.orx  setf rexx
1503 " R (Splus)
1504 if has("fname_case")
1505   au BufNewFile,BufRead *.s,*.S                 setf r
1506 else
1507   au BufNewFile,BufRead *.s                     setf r
1508 endif
1510 " R Help file
1511 if has("fname_case")
1512   au BufNewFile,BufRead *.rd,*.Rd               setf rhelp
1513 else
1514   au BufNewFile,BufRead *.rd                    setf rhelp
1515 endif
1517 " R noweb file
1518 if has("fname_case")
1519   au BufNewFile,BufRead *.Rnw,*.rnw,*.Snw,*.snw         setf rnoweb
1520 else
1521   au BufNewFile,BufRead *.rnw,*.snw                     setf rnoweb
1522 endif
1524 " Rexx, Rebol or R
1525 au BufNewFile,BufRead *.r,*.R                   call s:FTr()
1527 func! s:FTr()
1528   let max = line("$") > 50 ? 50 : line("$")
1530   for n in range(1, max)
1531     " Rebol is easy to recognize, check for that first
1532     if getline(n) =~? '\<REBOL\>'
1533       setf rebol
1534       return
1535     endif
1536   endfor
1538   for n in range(1, max)
1539     " R has # comments
1540     if getline(n) =~ '^\s*#'
1541       setf r
1542       return
1543     endif
1544     " Rexx has /* comments */
1545     if getline(n) =~ '^\s*/\*'
1546       setf rexx
1547       return
1548     endif
1549   endfor
1551   " Nothing recognized, assume Rexx
1552   setf rexx
1553 endfunc
1555 " Remind
1556 au BufNewFile,BufRead .reminders*               call s:StarSetf('remind')
1558 " Resolv.conf
1559 au BufNewFile,BufRead resolv.conf               setf resolv
1561 " Relax NG Compact
1562 au BufNewFile,BufRead *.rnc                     setf rnc
1564 " RPL/2
1565 au BufNewFile,BufRead *.rpl                     setf rpl
1567 " Robots.txt
1568 au BufNewFile,BufRead robots.txt                setf robots
1570 " Rpcgen
1571 au BufNewFile,BufRead *.x                       setf rpcgen
1573 " reStructuredText Documentation Format
1574 au BufNewFile,BufRead *.rst                     setf rst
1576 " RTF
1577 au BufNewFile,BufRead *.rtf                     setf rtf
1579 " Interactive Ruby shell
1580 au BufNewFile,BufRead .irbrc,irbrc              setf ruby
1582 " Ruby
1583 au BufNewFile,BufRead *.rb,*.rbw,*.gem,*.gemspec        setf ruby
1585 " Ruby on Rails
1586 au BufNewFile,BufRead *.builder,*.rxml,*.rjs    setf ruby
1588 " Rantfile and Rakefile is like Ruby
1589 au BufNewFile,BufRead [rR]antfile,*.rant,[rR]akefile,*.rake     setf ruby
1591 " S-lang (or shader language!)
1592 au BufNewFile,BufRead *.sl                      setf slang
1594 " Samba config
1595 au BufNewFile,BufRead smb.conf                  setf samba
1597 " SAS script
1598 au BufNewFile,BufRead *.sas                     setf sas
1600 " Sass
1601 au BufNewFile,BufRead *.sass                    setf sass
1603 " Sather
1604 au BufNewFile,BufRead *.sa                      setf sather
1606 " Scilab
1607 au BufNewFile,BufRead *.sci,*.sce               setf scilab
1609 " SD: Streaming Descriptors
1610 au BufNewFile,BufRead *.sd                      setf sd
1612 " SDL
1613 au BufNewFile,BufRead *.sdl,*.pr                setf sdl
1615 " sed
1616 au BufNewFile,BufRead *.sed                     setf sed
1618 " Sieve (RFC 3028)
1619 au BufNewFile,BufRead *.siv                     setf sieve
1621 " Sendmail
1622 au BufNewFile,BufRead sendmail.cf               setf sm
1624 " Sendmail .mc files are actually m4.  Could also be MS Message text file.
1625 au BufNewFile,BufRead *.mc                      call s:McSetf()
1627 func! s:McSetf()
1628   " Rely on the file to start with a comment.
1629   " MS message text files use ';', Sendmail files use '#' or 'dnl'
1630   for lnum in range(1, min([line("$"), 20]))
1631     let line = getline(lnum)
1632     if line =~ '^\s*\(#\|dnl\)'
1633       setf m4  " Sendmail .mc file
1634       return
1635     elseif line =~ '^\s*;'
1636       setf msmessages  " MS Message text file
1637       return
1638     endif
1639   endfor
1640   setf m4  " Default: Sendmail .mc file
1641 endfunc
1643 " Services
1644 au BufNewFile,BufRead /etc/services             setf services
1646 " Service Location config
1647 au BufNewFile,BufRead /etc/slp.conf             setf slpconf
1649 " Service Location registration
1650 au BufNewFile,BufRead /etc/slp.reg              setf slpreg
1652 " Service Location SPI
1653 au BufNewFile,BufRead /etc/slp.spi              setf slpspi
1655 " Setserial config
1656 au BufNewFile,BufRead /etc/serial.conf          setf setserial
1658 " SGML
1659 au BufNewFile,BufRead *.sgm,*.sgml
1660         \ if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'linuxdoc' |
1661         \   setf sgmllnx |
1662         \ elseif getline(1) =~ '<!DOCTYPE.*DocBook' || getline(2) =~ '<!DOCTYPE.*DocBook' |
1663         \   let b:docbk_type="sgml" |
1664         \   setf docbk |
1665         \ else |
1666         \   setf sgml |
1667         \ endif
1669 " SGMLDECL
1670 au BufNewFile,BufRead *.decl,*.dcl,*.dec
1671         \ if getline(1).getline(2).getline(3) =~? '^<!SGML' |
1672         \    setf sgmldecl |
1673         \ endif
1675 " SGML catalog file
1676 au BufNewFile,BufRead catalog                   setf catalog
1677 au BufNewFile,BufRead sgml.catalog*             call s:StarSetf('catalog')
1679 " Shell scripts (sh, ksh, bash, bash2, csh); Allow .profile_foo etc.
1680 " Gentoo ebuilds are actually bash scripts
1681 au BufNewFile,BufRead .bashrc*,bashrc,bash.bashrc,.bash_profile*,.bash_logout*,*.bash,*.ebuild call SetFileTypeSH("bash")
1682 au BufNewFile,BufRead .kshrc*,*.ksh call SetFileTypeSH("ksh")
1683 au BufNewFile,BufRead /etc/profile,.profile*,*.sh,*.env call SetFileTypeSH(getline(1))
1685 " Also called from scripts.vim.
1686 func! SetFileTypeSH(name)
1687   if expand("<amatch>") =~ g:ft_ignore_pat
1688     return
1689   endif
1690   if a:name =~ '\<ksh\>'
1691     let b:is_kornshell = 1
1692     if exists("b:is_bash")
1693       unlet b:is_bash
1694     endif
1695     if exists("b:is_sh")
1696       unlet b:is_sh
1697     endif
1698   elseif exists("g:bash_is_sh") || a:name =~ '\<bash\>' || a:name =~ '\<bash2\>'
1699     let b:is_bash = 1
1700     if exists("b:is_kornshell")
1701       unlet b:is_kornshell
1702     endif
1703     if exists("b:is_sh")
1704       unlet b:is_sh
1705     endif
1706   elseif a:name =~ '\<sh\>'
1707     let b:is_sh = 1
1708     if exists("b:is_kornshell")
1709       unlet b:is_kornshell
1710     endif
1711     if exists("b:is_bash")
1712       unlet b:is_bash
1713     endif
1714   endif
1715   call SetFileTypeShell("sh")
1716 endfunc
1718 " For shell-like file types, check for an "exec" command hidden in a comment,
1719 " as used for Tcl.
1720 " Also called from scripts.vim, thus can't be local to this script.
1721 func! SetFileTypeShell(name)
1722   if expand("<amatch>") =~ g:ft_ignore_pat
1723     return
1724   endif
1725   let l = 2
1726   while l < 20 && l < line("$") && getline(l) =~ '^\s*\(#\|$\)'
1727     " Skip empty and comment lines.
1728     let l = l + 1
1729   endwhile
1730   if l < line("$") && getline(l) =~ '\s*exec\s' && getline(l - 1) =~ '^\s*#.*\\$'
1731     " Found an "exec" line after a comment with continuation
1732     let n = substitute(getline(l),'\s*exec\s\+\([^ ]*/\)\=', '', '')
1733     if n =~ '\<tclsh\|\<wish'
1734       setf tcl
1735       return
1736     endif
1737   endif
1738   exe "setf " . a:name
1739 endfunc
1741 " tcsh scripts
1742 au BufNewFile,BufRead .tcshrc*,*.tcsh,tcsh.tcshrc,tcsh.login    call SetFileTypeShell("tcsh")
1744 " csh scripts, but might also be tcsh scripts (on some systems csh is tcsh)
1745 au BufNewFile,BufRead .login*,.cshrc*,csh.cshrc,csh.login,csh.logout,*.csh,.alias  call s:CSH()
1747 func! s:CSH()
1748   if exists("g:filetype_csh")
1749     call SetFileTypeShell(g:filetype_csh)
1750   elseif &shell =~ "tcsh"
1751     call SetFileTypeShell("tcsh")
1752   else
1753     call SetFileTypeShell("csh")
1754   endif
1755 endfunc
1757 " Z-Shell script
1758 au BufNewFile,BufRead .zprofile,/etc/zprofile,.zfbfmarks  setf zsh
1759 au BufNewFile,BufRead .zsh*,.zlog*,.zcompdump*  call s:StarSetf('zsh')
1760 au BufNewFile,BufRead *.zsh                     setf zsh
1762 " Scheme
1763 au BufNewFile,BufRead *.scm,*.ss                setf scheme
1765 " Screen RC
1766 au BufNewFile,BufRead .screenrc,screenrc        setf screen
1768 " Simula
1769 au BufNewFile,BufRead *.sim                     setf simula
1771 " SINDA
1772 au BufNewFile,BufRead *.sin,*.s85               setf sinda
1774 " SiSU
1775 au BufNewFile,BufRead *.sst,*.ssm,*.ssi,*.-sst,*._sst setf sisu
1776 au BufNewFile,BufRead *.sst.meta,*.-sst.meta,*._sst.meta setf sisu
1778 " SKILL
1779 au BufNewFile,BufRead *.il,*.ils,*.cdf          setf skill
1781 " SLRN
1782 au BufNewFile,BufRead .slrnrc                   setf slrnrc
1783 au BufNewFile,BufRead *.score                   setf slrnsc
1785 " Smalltalk (and TeX)
1786 au BufNewFile,BufRead *.st                      setf st
1787 au BufNewFile,BufRead *.cls
1788         \ if getline(1) =~ '^%' |
1789         \  setf tex |
1790         \ else |
1791         \  setf st |
1792         \ endif
1794 " Smarty templates
1795 au BufNewFile,BufRead *.tpl                     setf smarty
1797 " SMIL or XML
1798 au BufNewFile,BufRead *.smil
1799         \ if getline(1) =~ '<?\s*xml.*?>' |
1800         \   setf xml |
1801         \ else |
1802         \   setf smil |
1803         \ endif
1805 " SMIL or SNMP MIB file
1806 au BufNewFile,BufRead *.smi
1807         \ if getline(1) =~ '\<smil\>' |
1808         \   setf smil |
1809         \ else |
1810         \   setf mib |
1811         \ endif
1813 " SMITH
1814 au BufNewFile,BufRead *.smt,*.smith             setf smith
1816 " Snobol4 and spitbol
1817 au BufNewFile,BufRead *.sno,*.spt               setf snobol4
1819 " SNMP MIB files
1820 au BufNewFile,BufRead *.mib,*.my                setf mib
1822 " Snort Configuration
1823 au BufNewFile,BufRead *.hog,snort.conf,vision.conf      setf hog
1824 au BufNewFile,BufRead *.rules                   call s:FTRules()
1826 let s:ft_rules_udev_rules_pattern = '^\s*\cudev_rules\s*=\s*"\([^"]\{-1,}\)/*".*'
1827 func! s:FTRules()
1828   if expand('<amatch>:p') =~ '^/etc/udev/\%(rules\.d/\)\=.*\.rules$'
1829     setf udevrules
1830     return
1831   endif
1832   try
1833     let config_lines = readfile('/etc/udev/udev.conf')
1834   catch /^Vim\%((\a\+)\)\=:E484/
1835     setf hog
1836     return
1837   endtry
1838   let dir = expand('<amatch>:p:h')
1839   for line in config_lines
1840     if line =~ s:ft_rules_udev_rules_pattern
1841       let udev_rules = substitute(line, s:ft_rules_udev_rules_pattern, '\1', "")
1842       if dir == udev_rules
1843         setf udevrules
1844       endif
1845       break
1846     endif
1847   endfor
1848   setf hog
1849 endfunc
1852 " Spec (Linux RPM)
1853 au BufNewFile,BufRead *.spec                    setf spec
1855 " Speedup (AspenTech plant simulator)
1856 au BufNewFile,BufRead *.speedup,*.spdata,*.spd  setf spup
1858 " Slice
1859 au BufNewFile,BufRead *.ice                     setf slice
1861 " Spice
1862 au BufNewFile,BufRead *.sp,*.spice              setf spice
1864 " Spyce
1865 au BufNewFile,BufRead *.spy,*.spi               setf spyce
1867 " Squid
1868 au BufNewFile,BufRead squid.conf                setf squid
1870 " SQL for Oracle Designer
1871 au BufNewFile,BufRead *.tyb,*.typ,*.tyc,*.pkb,*.pks     setf sql
1873 " SQL
1874 au BufNewFile,BufRead *.sql                     call s:SQL()
1876 func! s:SQL()
1877   if exists("g:filetype_sql")
1878     exe "setf " . g:filetype_sql
1879   else
1880     setf sql
1881   endif
1882 endfunc
1884 " SQLJ
1885 au BufNewFile,BufRead *.sqlj                    setf sqlj
1887 " SQR
1888 au BufNewFile,BufRead *.sqr,*.sqi               setf sqr
1890 " OpenSSH configuration
1891 au BufNewFile,BufRead ssh_config,*/.ssh/config  setf sshconfig
1893 " OpenSSH server configuration
1894 au BufNewFile,BufRead sshd_config               setf sshdconfig
1896 " Stata
1897 au BufNewFile,BufRead *.ado,*.class,*.do,*.imata,*.mata   setf stata
1899 " SMCL
1900 au BufNewFile,BufRead *.hlp,*.ihlp,*.smcl       setf smcl
1902 " Stored Procedures
1903 au BufNewFile,BufRead *.stp                     setf stp
1905 " Standard ML
1906 au BufNewFile,BufRead *.sml                     setf sml
1908 " Sratus VOS command macro
1909 au BufNewFile,BufRead *.cm                      setf voscm
1911 " Sysctl
1912 au BufNewFile,BufRead /etc/sysctl.conf          setf sysctl
1914 " Sudoers
1915 au BufNewFile,BufRead /etc/sudoers,sudoers.tmp  setf sudoers
1917 " If the file has an extension of 't' and is in a directory 't' then it is
1918 " almost certainly a Perl test file.
1919 " If the first line starts with '#' and contains 'perl' it's probably a Perl
1920 " file.
1921 " (Slow test) If a file contains a 'use' statement then it is almost certainly
1922 " a Perl file.
1923 func! s:FTperl()
1924   if expand("%:e") == 't' && expand("%:p:h:t") == 't'
1925     setf perl
1926     return 1
1927   endif
1928   if getline(1)[0] == '#' && getline(1) =~ 'perl'
1929     setf perl
1930     return 1
1931   endif
1932   if search('^use\s\s*\k', 'nc', 30)
1933     setf perl
1934     return 1
1935   endif
1936   return 0
1937 endfunc
1939 " Tads (or Nroff or Perl test file)
1940 au BufNewFile,BufRead *.t
1941         \ if !s:FTnroff() && !s:FTperl() | setf tads | endif
1943 " Tags
1944 au BufNewFile,BufRead tags                      setf tags
1946 " TAK
1947 au BufNewFile,BufRead *.tak                     setf tak
1949 " Tcl (JACL too)
1950 au BufNewFile,BufRead *.tcl,*.tk,*.itcl,*.itk,*.jacl    setf tcl
1952 " TealInfo
1953 au BufNewFile,BufRead *.tli                     setf tli
1955 " Telix Salt
1956 au BufNewFile,BufRead *.slt                     setf tsalt
1958 " Terminfo
1959 au BufNewFile,BufRead *.ti                      setf terminfo
1961 " TeX
1962 au BufNewFile,BufRead *.latex,*.sty,*.dtx,*.ltx,*.bbl   setf tex
1963 au BufNewFile,BufRead *.tex                     call s:FTtex()
1965 " Choose context, plaintex, or tex (LaTeX) based on these rules:
1966 " 1. Check the first line of the file for "%&<format>".
1967 " 2. Check the first 1000 non-comment lines for LaTeX or ConTeXt keywords.
1968 " 3. Default to "latex" or to g:tex_flavor, can be set in user's vimrc.
1969 func! s:FTtex()
1970   let firstline = getline(1)
1971   if firstline =~ '^%&\s*\a\+'
1972     let format = tolower(matchstr(firstline, '\a\+'))
1973     let format = substitute(format, 'pdf', '', '')
1974     if format == 'tex'
1975       let format = 'plain'
1976     endif
1977   else
1978     " Default value, may be changed later:
1979     let format = exists("g:tex_flavor") ? g:tex_flavor : 'plain'
1980     " Save position, go to the top of the file, find first non-comment line.
1981     let save_cursor = getpos('.')
1982     call cursor(1,1)
1983     let firstNC = search('^\s*[^[:space:]%]', 'c', 1000)
1984     if firstNC " Check the next thousand lines for a LaTeX or ConTeXt keyword.
1985       let lpat = 'documentclass\>\|usepackage\>\|begin{\|newcommand\>\|renewcommand\>'
1986       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\>'
1987       let kwline = search('^\s*\\\%(' . lpat . '\)\|^\s*\\\(' . cpat . '\)',
1988                               \ 'cnp', firstNC + 1000)
1989       if kwline == 1    " lpat matched
1990         let format = 'latex'
1991       elseif kwline == 2        " cpat matched
1992         let format = 'context'
1993       endif             " If neither matched, keep default set above.
1994       " let lline = search('^\s*\\\%(' . lpat . '\)', 'cn', firstNC + 1000)
1995       " let cline = search('^\s*\\\%(' . cpat . '\)', 'cn', firstNC + 1000)
1996       " if cline > 0
1997       "   let format = 'context'
1998       " endif
1999       " if lline > 0 && (cline == 0 || cline > lline)
2000       "   let format = 'tex'
2001       " endif
2002     endif " firstNC
2003     call setpos('.', save_cursor)
2004   endif " firstline =~ '^%&\s*\a\+'
2006   " Translation from formats to file types.  TODO:  add AMSTeX, RevTex, others?
2007   if format == 'plain'
2008     setf plaintex
2009   elseif format == 'context'
2010     setf context
2011   else " probably LaTeX
2012     setf tex
2013   endif
2014   return
2015 endfunc
2017 " ConTeXt
2018 au BufNewFile,BufRead tex/context/*/*.tex,*.mkii,*.mkiv   setf context
2020 " Texinfo
2021 au BufNewFile,BufRead *.texinfo,*.texi,*.txi    setf texinfo
2023 " TeX configuration
2024 au BufNewFile,BufRead texmf.cnf                 setf texmf
2026 " Tidy config
2027 au BufNewFile,BufRead .tidyrc,tidyrc            setf tidy
2029 " TF mud client
2030 au BufNewFile,BufRead *.tf,.tfrc,tfrc           setf tf
2032 " TPP - Text Presentation Program
2033 au BufNewFile,BufReadPost *.tpp                 setf tpp
2035 " Trustees
2036 au BufNewFile,BufRead trustees.conf             setf trustees
2038 " TSS - Geometry
2039 au BufNewFile,BufReadPost *.tssgm               setf tssgm
2041 " TSS - Optics
2042 au BufNewFile,BufReadPost *.tssop               setf tssop
2044 " TSS - Command Line (temporary)
2045 au BufNewFile,BufReadPost *.tsscl               setf tsscl
2047 " Motif UIT/UIL files
2048 au BufNewFile,BufRead *.uit,*.uil               setf uil
2050 " Udev conf
2051 au BufNewFile,BufRead /etc/udev/udev.conf       setf udevconf
2053 " Udev permissions
2054 au BufNewFile,BufRead /etc/udev/permissions.d/*.permissions setf udevperm
2056 " Udev symlinks config
2057 au BufNewFile,BufRead /etc/udev/cdsymlinks.conf setf sh
2059 " UnrealScript
2060 au BufNewFile,BufRead *.uc                      setf uc
2062 " Updatedb
2063 au BufNewFile,BufRead /etc/updatedb.conf        setf updatedb
2065 " Vera
2066 au BufNewFile,BufRead *.vr,*.vri,*.vrh          setf vera
2068 " Verilog HDL
2069 au BufNewFile,BufRead *.v                       setf verilog
2071 " Verilog-AMS HDL
2072 au BufNewFile,BufRead *.va,*.vams               setf verilogams
2074 " VHDL
2075 au BufNewFile,BufRead *.hdl,*.vhd,*.vhdl,*.vbe,*.vst  setf vhdl
2076 au BufNewFile,BufRead *.vhdl_[0-9]*             call s:StarSetf('vhdl')
2078 " Vim script
2079 au BufNewFile,BufRead *.vim,*.vba,.exrc,_exrc   setf vim
2081 " Viminfo file
2082 au BufNewFile,BufRead .viminfo,_viminfo         setf viminfo
2084 " Virata Config Script File or Drupal module
2085 au BufRead,BufNewFile *.hw,*.module,*.pkg
2086         \ if getline(1) =~ '<?php' |
2087         \   setf php |
2088         \ else |
2089         \   setf virata |
2090         \ endif
2092 " Visual Basic (also uses *.bas) or FORM
2093 au BufNewFile,BufRead *.frm                     call s:FTVB("form")
2095 " SaxBasic is close to Visual Basic
2096 au BufNewFile,BufRead *.sba                     setf vb
2098 " Vgrindefs file
2099 au BufNewFile,BufRead vgrindefs                 setf vgrindefs
2101 " VRML V1.0c
2102 au BufNewFile,BufRead *.wrl                     setf vrml
2104 " Webmacro
2105 au BufNewFile,BufRead *.wm                      setf webmacro
2107 " Wget config
2108 au BufNewFile,BufRead .wgetrc,wgetrc            setf wget
2110 " Website MetaLanguage
2111 au BufNewFile,BufRead *.wml                     setf wml
2113 " Winbatch
2114 au BufNewFile,BufRead *.wbt                     setf winbatch
2116 " WSML
2117 au BufNewFile,BufRead *.wsml                    setf wsml
2119 " WvDial
2120 au BufNewFile,BufRead wvdial.conf,.wvdialrc     setf wvdial
2122 " CVS RC file
2123 au BufNewFile,BufRead .cvsrc                    setf cvsrc
2125 " CVS commit file
2126 au BufNewFile,BufRead cvs\d\+                   setf cvs
2128 " WEB (*.web is also used for Winbatch: Guess, based on expecting "%" comment
2129 " lines in a WEB file).
2130 au BufNewFile,BufRead *.web
2131         \ if getline(1)[0].getline(2)[0].getline(3)[0].getline(4)[0].getline(5)[0] =~ "%" |
2132         \   setf web |
2133         \ else |
2134         \   setf winbatch |
2135         \ endif
2137 " Windows Scripting Host and Windows Script Component
2138 au BufNewFile,BufRead *.ws[fc]                  setf wsh
2140 " XHTML
2141 au BufNewFile,BufRead *.xhtml,*.xht             setf xhtml
2143 " X Pixmap (dynamically sets colors, use BufEnter to make it work better)
2144 au BufEnter *.xpm
2145         \ if getline(1) =~ "XPM2" |
2146         \   setf xpm2 |
2147         \ else |
2148         \   setf xpm |
2149         \ endif
2150 au BufEnter *.xpm2                              setf xpm2
2152 " XFree86 config
2153 au BufNewFile,BufRead XF86Config
2154         \ if getline(1) =~ '\<XConfigurator\>' |
2155         \   let b:xf86c_xfree86_version = 3 |
2156         \ endif |
2157         \ setf xf86conf
2159 " Xorg config
2160 au BufNewFile,BufRead xorg.conf,xorg.conf-4     let b:xf86c_xfree86_version = 4 | setf xf86conf
2162 " Xinetd conf
2163 au BufNewFile,BufRead /etc/xinetd.conf          setf xinetd
2165 " XS Perl extension interface language
2166 au BufNewFile,BufRead *.xs                      setf xs
2168 " X resources file
2169 au BufNewFile,BufRead .Xdefaults,.Xpdefaults,.Xresources,xdm-config,*.ad setf xdefaults
2171 " Xmath
2172 au BufNewFile,BufRead *.msc,*.msf               setf xmath
2173 au BufNewFile,BufRead *.ms
2174         \ if !s:FTnroff() | setf xmath | endif
2176 " XML  specific variants: docbk and xbl
2177 au BufNewFile,BufRead *.xml                     call s:FTxml()
2179 func! s:FTxml()
2180   let n = 1
2181   while n < 100 && n < line("$")
2182     let line = getline(n)
2183     if line =~ '<!DOCTYPE.*DocBook'
2184       let b:docbk_type = "xml"
2185       setf docbk
2186       return
2187     endif
2188     if line =~ 'xmlns:xbl="http://www.mozilla.org/xbl"'
2189       setf xbl
2190       return
2191     endif
2192     let n += 1
2193   endwhile
2194   setf xml
2195 endfunc
2197 " XMI (holding UML models) is also XML
2198 au BufNewFile,BufRead *.xmi                     setf xml
2200 " CSPROJ files are Visual Studio.NET's XML-based project config files
2201 au BufNewFile,BufRead *.csproj,*.csproj.user    setf xml
2203 " Qt Linguist translation source and Qt User Interface Files are XML
2204 au BufNewFile,BufRead *.ts,*.ui                 setf xml
2206 " TPM's are RDF-based descriptions of TeX packages (Nikolai Weibull)
2207 au BufNewFile,BufRead *.tpm                     setf xml
2209 " Xdg menus
2210 au BufNewFile,BufRead /etc/xdg/menus/*.menu     setf xml
2212 " ATI graphics driver configuration
2213 au BufNewFile,BufRead fglrxrc                   setf xml
2215 " XLIFF (XML Localisation Interchange File Format) is also XML
2216 au BufNewFile,BufRead *.xlf                     setf xml
2217 au BufNewFile,BufRead *.xliff                   setf xml
2219 " X11 xmodmap (also see below)
2220 au BufNewFile,BufRead *Xmodmap                  setf xmodmap
2222 " Xquery
2223 au BufNewFile,BufRead *.xq,*.xql,*.xqm,*.xquery,*.xqy   setf xquery
2225 " XSD
2226 au BufNewFile,BufRead *.xsd                     setf xsd
2228 " Xslt
2229 au BufNewFile,BufRead *.xsl,*.xslt              setf xslt
2231 " Yacc
2232 au BufNewFile,BufRead *.yy                      setf yacc
2234 " Yacc or racc
2235 au BufNewFile,BufRead *.y                       call s:FTy()
2237 func! s:FTy()
2238   let n = 1
2239   while n < 100 && n < line("$")
2240     let line = getline(n)
2241     if line =~ '^\s*%'
2242       setf yacc
2243       return
2244     endif
2245     if getline(n) =~ '^\s*\(#\|class\>\)' && getline(n) !~ '^\s*#\s*include'
2246       setf racc
2247       return
2248     endif
2249     let n = n + 1
2250   endwhile
2251   setf yacc
2252 endfunc
2255 " Yaml
2256 au BufNewFile,BufRead *.yaml,*.yml              setf yaml
2258 " Zope
2259 "   dtml (zope dynamic template markup language), pt (zope page template),
2260 "   cpt (zope form controller page template)
2261 au BufNewFile,BufRead *.dtml,*.pt,*.cpt         call s:FThtml()
2262 "   zsql (zope sql method)
2263 au BufNewFile,BufRead *.zsql                    call s:SQL()
2265 " Z80 assembler asz80
2266 au BufNewFile,BufRead *.z8a                     setf z8a
2268 augroup END
2271 " Source the user-specified filetype file, for backwards compatibility with
2272 " Vim 5.x.
2273 if exists("myfiletypefile") && filereadable(expand(myfiletypefile))
2274   execute "source " . myfiletypefile
2275 endif
2278 " Check for "*" after loading myfiletypefile, so that scripts.vim is only used
2279 " when there are no matching file name extensions.
2280 " Don't do this for compressed files.
2281 augroup filetypedetect
2282 au BufNewFile,BufRead *
2283         \ if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat
2284         \ | runtime! scripts.vim | endif
2285 au StdinReadPost * if !did_filetype() | runtime! scripts.vim | endif
2288 " Extra checks for when no filetype has been detected now.  Mostly used for
2289 " patterns that end in "*".  E.g., "zsh*" matches "zsh.vim", but that's a Vim
2290 " script file.
2291 " Most of these should call s:StarSetf() to avoid names ending in .gz and the
2292 " like are used.
2294 " More Apache files.
2295 au BufNewFile,BufRead /etc/apache2/conf.*/*,/etc/apache2/sites-*/*,/etc/apache2/mods-*/*                call s:StarSetf('apache')
2297 " Asterisk config file
2298 au BufNewFile,BufRead *asterisk/*.conf*         call s:StarSetf('asterisk')
2299 au BufNewFile,BufRead *asterisk*/*voicemail.conf* call s:StarSetf('asteriskvm')
2301 " Bazaar version control
2302 au BufNewFile,BufRead bzr_log.*                 setf bzr
2304 " BIND zone
2305 au BufNewFile,BufRead */named/db.*,*/bind/db.*  call s:StarSetf('bindzone')
2307 " Changelog
2308 au BufNewFile,BufRead [cC]hange[lL]og*
2309         \ if getline(1) =~ '; urgency='
2310         \|  call s:StarSetf('debchangelog')
2311         \|else
2312         \|  call s:StarSetf('changelog')
2313         \|endif
2315 " Crontab
2316 au BufNewFile,BufRead crontab,crontab.*,/etc/cron.d/*           call s:StarSetf('crontab')
2318 " Debian Sources.list
2319 au BufNewFile,BufRead /etc/apt/sources.list.d/* call s:StarSetf('debsources')
2321 " Dracula
2322 au BufNewFile,BufRead drac.*                    call s:StarSetf('dracula')
2324 " Fvwm
2325 au BufNewFile,BufRead */.fvwm/*                 call s:StarSetf('fvwm')
2326 au BufNewFile,BufRead *fvwmrc*,*fvwm95*.hook
2327         \ let b:fvwm_version = 1 | call s:StarSetf('fvwm')
2328 au BufNewFile,BufRead *fvwm2rc*
2329         \ if expand("<afile>:e") == "m4"
2330         \|  call s:StarSetf('fvwm2m4')
2331         \|else
2332         \|  let b:fvwm_version = 2 | call s:StarSetf('fvwm')
2333         \|endif
2335 " GTK RC
2336 au BufNewFile,BufRead .gtkrc*,gtkrc*            call s:StarSetf('gtkrc')
2338 " Jam
2339 au BufNewFile,BufRead Prl*.*,JAM*.*             call s:StarSetf('jam')
2341 " Jargon
2342 au! BufNewFile,BufRead *jarg*
2343         \ if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'THIS IS THE JARGON FILE'
2344         \|  call s:StarSetf('jargon')
2345         \|endif
2347 " Kconfig
2348 au BufNewFile,BufRead Kconfig.*                 call s:StarSetf('kconfig')
2350 " Makefile
2351 au BufNewFile,BufRead [mM]akefile*              call s:StarSetf('make')
2353 " Ruby Makefile
2354 au BufNewFile,BufRead [rR]akefile*              call s:StarSetf('ruby')
2356 " Mail (also matches muttrc.vim, so this is below the other checks)
2357 au BufNewFile,BufRead mutt[[:alnum:]._-]\{6\}   setf mail
2359 " Modconf
2360 au BufNewFile,BufRead /etc/modprobe.*           call s:StarSetf('modconf')
2362 " Mutt setup file
2363 au BufNewFile,BufRead .mutt{ng,}rc*,*/.mutt{ng,}/mutt{ng,}rc*   call s:StarSetf('muttrc')
2364 au BufNewFile,BufRead mutt{ng,}rc*,Mutt{ng,}rc*         call s:StarSetf('muttrc')
2366 " Nroff macros
2367 au BufNewFile,BufRead tmac.*                    call s:StarSetf('nroff')
2369 " Pam conf
2370 au BufNewFile,BufRead /etc/pam.d/*              call s:StarSetf('pamconf')
2372 " Printcap and Termcap
2373 au BufNewFile,BufRead *printcap*
2374         \ if !did_filetype()
2375         \|  let b:ptcap_type = "print" | call s:StarSetf('ptcap')
2376         \|endif
2377 au BufNewFile,BufRead *termcap*
2378         \ if !did_filetype()
2379         \|  let b:ptcap_type = "term" | call s:StarSetf('ptcap')
2380         \|endif
2382 " Vim script
2383 au BufNewFile,BufRead *vimrc*                   call s:StarSetf('vim')
2385 " Subversion commit file
2386 au BufNewFile,BufRead svn-commit*.tmp           setf svn
2388 " X resources file
2389 au BufNewFile,BufRead Xresources*,*/app-defaults/*,*/Xresources/* call s:StarSetf('xdefaults')
2391 " XFree86 config
2392 au BufNewFile,BufRead XF86Config-4*
2393         \ let b:xf86c_xfree86_version = 4 | call s:StarSetf('xf86conf')
2394 au BufNewFile,BufRead XF86Config*
2395         \ if getline(1) =~ '\<XConfigurator\>'
2396         \|  let b:xf86c_xfree86_version = 3
2397         \|endif
2398         \|call s:StarSetf('xf86conf')
2400 " X11 xmodmap
2401 au BufNewFile,BufRead *xmodmap*                 call s:StarSetf('xmodmap')
2403 " Xinetd conf
2404 au BufNewFile,BufRead /etc/xinetd.d/*           call s:StarSetf('xinetd')
2406 " Z-Shell script
2407 au BufNewFile,BufRead zsh*,zlog*                call s:StarSetf('zsh')
2410 " Generic configuration file (check this last, it's just guessing!)
2411 au BufNewFile,BufRead,StdinReadPost *
2412         \ if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat
2413         \    && (getline(1) =~ '^#' || getline(2) =~ '^#' || getline(3) =~ '^#'
2414         \       || getline(4) =~ '^#' || getline(5) =~ '^#') |
2415         \   setf conf |
2416         \ endif
2418 " Use the plugin-filetype checks last, they may overrule any of the previously
2419 " detected filetypes.
2420 runtime! ftdetect/*.vim
2422 augroup END
2425 " If the GUI is already running, may still need to install the Syntax menu.
2426 " Don't do it when the 'M' flag is included in 'guioptions'.
2427 if has("menu") && has("gui_running")
2428       \ && !exists("did_install_syntax_menu") && &guioptions !~# "M"
2429   source <sfile>:p:h/menu.vim
2430 endif
2432 " Function called for testing all functions defined here.  These are
2433 " script-local, thus need to be executed here.
2434 " Returns a string with error messages (hopefully empty).
2435 func! TestFiletypeFuncs(testlist)
2436   let output = ''
2437   for f in a:testlist
2438     try
2439       exe f
2440     catch
2441       let output = output . "\n" . f . ": " . v:exception
2442     endtry
2443   endfor
2444   return output
2445 endfunc
2447 " Restore 'cpoptions'
2448 let &cpo = s:cpo_save
2449 unlet s:cpo_save