fortran.vim (5944B)
1 " Vim settings file 2 " Language: Fortran 2023 (and Fortran 2018, 2008, 2003, 95, 90, 77, 66) 3 " Version: (v55) 2023 December 22 4 " Maintainers: Ajit J. Thakkar <ajit@unb.ca>; <https://ajit.ext.unb.ca/> 5 " Joshua Hollett <j.hollett@uwinnipeg.ca> 6 " Usage: For instructions, do :help fortran-plugin from Vim 7 " Credits: 8 " Version 0.1 was created in September 2000 by Ajit Thakkar. 9 " Since then, useful suggestions and contributions have been made, in order, by: 10 " Stefano Zacchiroli, Hendrik Merx, Ben Fritz, David Barnett, Eisuke Kawashima, 11 " Doug Kearns, and Fritz Reese. 12 " Last Change: 2023 Dec 22 13 " 2024 Jan 14 by Vim Project (browsefilter) 14 " 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring') 15 16 " Only do these settings when not done yet for this buffer 17 if exists("b:did_ftplugin") 18 finish 19 endif 20 21 let s:cposet=&cpoptions 22 set cpoptions&vim 23 24 " Don't do other file type settings for this buffer 25 let b:did_ftplugin = 1 26 27 " Determine whether this is a fixed or free format source file 28 " if this hasn't been done yet using the priority: 29 " buffer-local value 30 " > global value 31 " > file extension as in Intel ifort, gcc (gfortran), NAG, Pathscale, and Cray compilers 32 if !exists("b:fortran_fixed_source") 33 if exists("fortran_free_source") 34 " User guarantees free source form 35 let b:fortran_fixed_source = 0 36 elseif exists("fortran_fixed_source") 37 " User guarantees fixed source form 38 let b:fortran_fixed_source = 1 39 elseif expand("%:e") =~? '^f\%(90\|95\|03\|08\)$' 40 " Free-form file extension defaults as in Intel ifort, gcc(gfortran), NAG, Pathscale, and Cray compilers 41 let b:fortran_fixed_source = 0 42 elseif expand("%:e") =~? '^\%(f\|f77\|for\)$' 43 " Fixed-form file extension defaults 44 let b:fortran_fixed_source = 1 45 else 46 " Modern fortran compilers still allow both fixed and free source form 47 " Assume fixed source form unless signs of free source form 48 " are detected in the first five columns of the first s:lmax lines. 49 " Detection becomes more accurate and time-consuming if more lines 50 " are checked. Increase the limit below if you keep lots of comments at 51 " the very top of each file and you have a fast computer. 52 let s:lmax = 500 53 if ( s:lmax > line("$") ) 54 let s:lmax = line("$") 55 endif 56 let b:fortran_fixed_source = 1 57 let s:ln=1 58 while s:ln <= s:lmax 59 let s:test = strpart(getline(s:ln),0,5) 60 if s:test !~ '^[Cc*]' && s:test !~ '^ *[!#]' && s:test =~ '[^ 0-9\t]' && s:test !~ '^[ 0-9]*\t' 61 let b:fortran_fixed_source = 0 62 break 63 endif 64 let s:ln = s:ln + 1 65 endwhile 66 unlet! s:lmax s:ln s:test 67 endif 68 endif 69 70 " Set comments and textwidth according to source type 71 if (b:fortran_fixed_source == 1) 72 setlocal comments=:!,:*,:C 73 " Fixed format requires a textwidth of 72 for code, 74 " but some vendor extensions allow longer lines 75 if exists("fortran_extended_line_length") 76 setlocal tw=132 77 else 78 " The use of columns 73-80 for sequence numbers is obsolete 79 " so almost all compilers allow a textwidth of 80 80 setlocal tw=80 81 " If you need to add "&" on continued lines so that the code is 82 " compatible with both free and fixed format, then you should do so 83 " in column 81 and uncomment the next line 84 " setlocal tw=81 85 endif 86 else 87 setlocal comments=:! 88 " Free format allows a textwidth of 132 89 setlocal tw=132 90 endif 91 92 " Set commentstring for foldmethod=marker 93 setlocal cms=!\ %s 94 95 " Tabs are not a good idea in Fortran so the default is to expand tabs 96 if !exists("fortran_have_tabs") 97 setlocal expandtab 98 endif 99 100 " Set 'formatoptions' to break text lines 101 setlocal fo+=t 102 103 setlocal include=^\\c#\\=\\s*include\\s\\+ 104 setlocal suffixesadd+=.f08,.f03,.f95,.f90,.for,.f,.F,.f77,.ftn,.fpp 105 106 " Define patterns for the matchit plugin 107 if !exists("b:match_words") 108 let s:notend = '\%(\<end\s\+\)\@<!' 109 let s:notselect = '\%(\<select\s\+\)\@<!' 110 let s:notelse = '\%(\<end\s\+\|\<else\s\+\)\@<!' 111 let s:notprocedure = '\%(\s\+procedure\>\)\@!' 112 let s:nothash = '\%(^\s*#\s*\)\@<!' 113 let b:match_ignorecase = 1 114 let b:match_words = 115 \ '(:),' . 116 \ s:notend .'\<select\s\+type\>:' . s:notselect. '\<type\|class\>:\<end\s*select\>,' . 117 \ s:notend .'\<select\s\+rank\>:' . s:notselect. '\<rank\>:\<end\s*select\>,' . 118 \ s:notend .'\<select\>:' . s:notselect. '\<case\>:\<end\s*select\>,' . 119 \ s:notelse . '\<if\s*(.\+)\s*then\>:' . 120 \ s:nothash . '\<else\s*\%(if\s*(.\+)\s*then\)\=\>:' . s:nothash . '\<end\s*if\>,'. 121 \ 'do\s\+\(\d\+\):\%(^\s*\)\@<=\1\s,'. 122 \ s:notend . '\<do\>:\<end\s*do\>,'. 123 \ s:notelse . '\<where\>:\<elsewhere\>:\<end\s*where\>,'. 124 \ s:notend . '\<type\s*[^(]:\<end\s*type\>,'. 125 \ s:notend . '\<forall\>:\<end\s*forall\>,'. 126 \ s:notend . '\<associate\>:\<end\s*associate\>,'. 127 \ s:notend . '\<change\s\+team\>:\<end\s*team\>,'. 128 \ s:notend . '\<critical\>:\<end\s*critical\>,'. 129 \ s:notend . '\<block\>:\<end\s*block\>,'. 130 \ s:notend . '\<enum\>:\<end\s*enum\>,'. 131 \ s:notend . '\<interface\>:\<end\s*interface\>,'. 132 \ s:notend . '\<subroutine\>:\<end\s*subroutine\>,'. 133 \ s:notend . '\<function\>:\<end\s*function\>,'. 134 \ s:notend . '\<module\>' . s:notprocedure . ':\<end\s*module\>,'. 135 \ s:notend . '\<program\>:\<end\s*program\>,'. 136 \ '\%(^\s*\)\@<=#\s*if\%(def\|ndef\)\=\>:\%(^\s*\)\@<=#\s*\%(elif\|else\)\>:\%(^\s*\)\@<=#\s*endif\>' 137 endif 138 139 " File filters for :browse e 140 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") 141 let b:browsefilter = "Fortran Files (*.f, *.for, *.f77, *.f90, *.f95, *.f03, *.f08, *.fpp, *.ftn)\t*.f;*.for;*.f77;*.f90;*.f95;*.f03;*.f08;*.fpp;*.ftn\n" 142 if has("win32") 143 let b:browsefilter .= "All Files (*.*)\t*\n" 144 else 145 let b:browsefilter .= "All Files (*)\t*\n" 146 endif 147 endif 148 149 let b:undo_ftplugin = "setl fo< com< tw< cms< et< inc< sua<" 150 \ . "| unlet! b:match_ignorecase b:match_words b:browsefilter" 151 152 let &cpoptions=s:cposet 153 unlet s:cposet 154 155 " vim:sw=2