1" Vim settings file 2" Language: Fortran90 (and Fortran95, Fortran77, F and elf90) 3" Version: 0.44 4" Last Change: 2003 May 18 5" URL: http://www.unb.ca/chem/ajit/ftplugin/fortran.vim 6" Maintainer: Ajit J. Thakkar <[email protected]>; <http://www.unb.ca/chem/ajit/> 7" Usage: Do :help fortran-plugin from Vim 8 9" Only do these settings when not done yet for this buffer 10if exists("b:did_ftplugin") 11 finish 12endif 13 14" Don't do other file type settings for this buffer 15let b:did_ftplugin = 1 16 17" Determine whether this is a fixed or free format source file 18" if this hasn't been done yet 19if !exists("b:fortran_fixed_source") 20 if exists("fortran_free_source") 21 " User guarantees free source form 22 let b:fortran_fixed_source = 0 23 elseif exists("fortran_fixed_source") 24 " User guarantees fixed source form 25 let b:fortran_fixed_source = 1 26 else 27 " f90 and f95 allow both fixed and free source form 28 " assume fixed source form unless signs of free source form 29 " are detected in the first five columns of the first 25 lines 30 " Detection becomes more accurate and time-consuming if more lines 31 " are checked. Increase the limit below if you keep lots of comments at 32 " the very top of each file and you have a fast computer 33 let s:lmax = 25 34 if ( s:lmax > line("$") ) 35 let s:lmax = line("$") 36 endif 37 let b:fortran_fixed_source = 1 38 let s:ln=1 39 while s:ln <= s:lmax 40 let s:test = strpart(getline(s:ln),0,5) 41 if s:test[0] !~ '[Cc*!#]' && s:test !~ '^ \+[!#]' && s:test =~ '[^ 0-9\t]' 42 let b:fortran_fixed_source = 0 43 break 44 endif 45 let s:ln = s:ln + 1 46 endwhile 47 endif 48endif 49 50" Set comments and textwidth according to source type 51if (b:fortran_fixed_source == 1) 52 setlocal comments=:!,:*,:C 53 " Fixed format requires a textwidth of 72 for code 54 setlocal tw=72 55 " If you need to add "&" on continued lines so that the code is 56 " compatible with both free and fixed format, then you should do so 57 " in column 73 and uncomment the next line 58 " setlocal tw=73 59else 60 setlocal comments=:! 61 " Free format allows a textwidth of 132 for code but 80 is more usual 62 setlocal tw=80 63endif 64 65" Set commentstring for foldmethod=marker 66setlocal cms=!%s 67 68" Tabs are not a good idea in Fortran so the default is to expand tabs 69if !exists("fortran_have_tabs") 70 setlocal expandtab 71endif 72 73" Set 'formatoptions' to break comment and text lines but allow long lines 74setlocal fo+=tcql 75 76setlocal include=^#\\=\\s*include\\s\\+ 77 78let s:cposet=&cpoptions 79set cpoptions-=C 80 81" Define patterns for the matchit plugin 82if !exists("b:match_words") 83 let s:notend = '\%(\<end\s\+\)\@<!' 84 let s:notselect = '\%(\<select\s\+\)\@<!' 85 let s:notelse = '\%(\<end\s\+\|\<else\s\+\)\@<!' 86 let b:match_ignorecase = 1 87 let b:match_words = 88 \ '\<select\s*case\>:' . s:notselect. '\<case\>:\<end\s*select\>,' . 89 \ s:notelse . '\<if\s*(.\+)\s*then\>:' . 90 \ '\<else\s*\%(if\s*(.\+)\s*then\)\=\>:\<end\s*if\>,'. 91 \ 'do\s\+\(\d\+\):\%(^\s*\)\@<=\1\s,'. 92 \ s:notend . '\<do\>:\<end\s*do\>,'. 93 \ s:notelse . '\<where\>:\<elsewhere\>:\<end\s*where\>,'. 94 \ s:notend . '\<type\s*[^(]:\<end\s*type\>,'. 95 \ s:notend . '\<interface\>:\<end\s*interface\>,'. 96 \ s:notend . '\<subroutine\>:\<end\s*subroutine\>,'. 97 \ s:notend . '\<function\>:\<end\s*function\>,'. 98 \ s:notend . '\<module\>:\<end\s*module\>,'. 99 \ s:notend . '\<program\>:\<end\s*program\>' 100endif 101 102" File filters for :browse e 103if has("gui_win32") && !exists("b:browsefilter") 104 let b:browsefilter = "Fortran Files (*.f;*.F;*.for;*.f77;*.f90;*.f95;*.fpp;*.ftn)\t*.f;*.F;*.for;*.f77;*.f90;*.f95;*.fpp;*.ftn\n" . 105 \ "All Files (*.*)\t*.*\n" 106endif 107 108let b:undo_ftplugin = "setl fo< com< tw< cms< et< inc<" 109 \ . "| unlet! b:match_ignorecase b:match_words b:browsefilter" 110 111let &cpoptions=s:cposet 112unlet s:cposet 113 114" vim:sw=2 115