home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / mac / vim55rt.sit / runtime / scripts.vim < prev    next >
Encoding:
Text File  |  1999-09-25  |  3.7 KB  |  137 lines  |  [TEXT/VIM!]

  1. " Vim support file to detect file types in scripts
  2. "
  3. " Maintainer:    Bram Moolenaar <Bram@vim.org>
  4. " Last change:    1999 Jul 09
  5.  
  6. " This file is called by an autocommand for every file that has just been
  7. " loaded into a buffer.  It checks if the type of file can be recognized by
  8. " the file contents.  The autocommand is in $VIMRUNTIME/filetype.vim.
  9.  
  10.  
  11. " Load the user defined scripts file first
  12. " Only do this when the FileType autocommand has not been triggered yet
  13. if !did_filetype() && exists("myscriptsfile") && file_readable(expand(myscriptsfile))
  14.   execute "source " . myscriptsfile
  15. endif
  16.  
  17. " Only do this when the FileType autocommand has not been triggered yet
  18. if !did_filetype()
  19.  
  20. " Bourne-like shell scripts: sh ksh bash
  21. if getline(1) =~ '^#!.*[/\\][bk]\=a\=sh\>'
  22.   if exists("is_bash")
  23.     unlet is_bash
  24.   endif
  25.   if exists("is_kornshell")
  26.     unlet is_kornshell
  27.   endif
  28.   " if bash is sh on your system as on Linux, you may prefer to
  29.   " add the following in your .vimrc file:
  30.   " let bash_is_sh=1
  31.   if exists("bash_is_sh") || getline(1) =~ '^#!.*[/\\]bash\>'
  32.     let is_bash=1
  33.   elseif getline(1) =~ '^#!.*[/\\]ksh\>'
  34.     let is_kornshell=1
  35.   endif
  36.   set ft=sh
  37.  
  38. " csh and tcsh scripts
  39. elseif getline(1) =~ '^#!.*[/\\]t\=csh\>'
  40.   set ft=csh
  41.  
  42. " Z shell scripts
  43. elseif getline(1) =~ '^#!.*[/\\]zsh\>'
  44.     \ || getline(1) =~ '^#compdef\>'
  45.     \ || getline(1) =~ '^#autoload\>'
  46.   set ft=zsh
  47.  
  48. " TCL scripts
  49. elseif getline(1) =~ '^#!.*[/\\]\(tclsh\|wish\|expectk\|itclsh\|itkwish\)\>'
  50.   set ft=tcl
  51.  
  52. " ELM Mail files
  53. elseif getline(1) =~ '^From [a-zA-Z][a-zA-Z_0-9\.=-]*\(@[^ ]*\)\= .*[12][09]\d\d$'
  54.   set ft=mail
  55.  
  56. " Expect scripts
  57. elseif getline(1) =~ '^#!.*[/\\]expect\>'
  58.   set ft=expect
  59.  
  60. " Gnuplot scripts
  61. elseif getline(1) =~ '^#!.*[/\\]gnuplot\>'
  62.   set ft=gnuplot
  63.  
  64. " Makefiles
  65. elseif getline(1) =~ '^#!.*[/\\][^/\\]*make\>'
  66.   set ft=make
  67.  
  68. " Perl
  69. elseif getline(1) =~ '^#!.*[/\\][^/\\]*perl[^/\\]*\>'
  70.   set ft=perl
  71.  
  72. " Python
  73. elseif getline(1) =~ '^#!.*[/\\][^/\\]*python[^/\\]*\>'
  74.   set ft=python
  75.  
  76. " sed
  77. elseif getline(1) =~ '^#!.*sed\>'
  78.   set ft=sed
  79.  
  80. " Vim scripts (must have '" vim' as the first line to trigger this)
  81. elseif getline(1) =~ '^" *[vV]im$'
  82.   set ft=vim
  83.  
  84. " Diff file:
  85. " - "diff" in first line (context diff)
  86. " - "Only in " in first line
  87. " - "--- " in first line and "+++ " in second line (unified diff).
  88. " - "*** " in first line and "--- " in second line (context diff).
  89. " - "# It was generated by makepatch " in the second line (makepatch diff).
  90. " - "Index: <filename>" in the first line (CVS file)
  91. elseif getline(1) =~ '^diff\>' || getline(1) =~ '^Only in '
  92.     \ || (getline(1) =~ '^--- ' && getline(2) =~ '^+++ ')
  93.     \ || (getline(1) =~ '^\*\*\* ' && getline(2) =~ '^--- ')
  94.     \ || getline(1) =~ '^\d\+\(,\d\+\)\=[cda]\d\+\>'
  95.     \ || getline(2) =~ '^# It was generated by makepatch '
  96.     \ || getline(1) =~ '^Index:\s\+\f\+$'
  97.   set ft=diff
  98.  
  99. " PostScript Files (must have %!PS as the first line, like a2ps output)
  100. elseif getline(1) =~ '^%![ \t]*PS'
  101.   set ft=postscr
  102.  
  103. " Awk scripts
  104. elseif getline(1) =~ '^#!.*awk\>'
  105.   set ft=awk
  106.  
  107. " M4 scripts: Guess there is a line that starts with "dnl".
  108. elseif getline(1) =~ '^\s*dnl\>'
  109.     \ || getline(2) =~ '^\s*dnl\>'
  110.     \ || getline(3) =~ '^\s*dnl\>'
  111.     \ || getline(4) =~ '^\s*dnl\>'
  112.     \ || getline(5) =~ '^\s*dnl\>'
  113.   set ft=m4
  114.  
  115. " AmigaDos scripts
  116. elseif $TERM == "amiga"
  117.     \ && (getline(1) =~ "^;" || getline(1) =~ '^\.[bB][rR][aA]')
  118.   set ft=amiga
  119.  
  120. " SiCAD scripts (must have procn or procd as the first line to trigger this)
  121. elseif getline(1) =~ '^ *[pP][rR][oO][cC][nNdD] *$'
  122.   set ft=sicad
  123.  
  124. " Purify log files start with "****  Purify"
  125. elseif getline(1) =~ '^\*\*\*\*  Purify'
  126.   set ft=purifylog
  127.  
  128. " XXD output
  129. elseif getline(1) =~ '^\x\{7}: \x\{4} \x\{4} '
  130.   set ft=xxd
  131.  
  132. endif
  133.  
  134. endif " !did_filetype()
  135.  
  136. " vim: ts=8 tw=0 sts=0
  137.