Indenting Fortran code in Vim -
i have fortran code looks this:
open(2,file=filenm(i),status='unknown') j=1,num_lines k=1,dime read(2,*) z(k) enddo if( j .ge. 1000 ) k=1,dime sumz(k)=sumz(k)+z(k) enddo nsteps=nsteps+1.0 endif enddo close(2)
as can see indentation not even, have this:
open(2,file=filenm(i),status='unknown') j=1,num_lines k=1,dime read(2,*) z(k) enddo if( j .ge. 1000 ) k=1,dime sumz(k)=sumz(k)+z(k) enddo nsteps=nsteps+1.0 endif enddo close(2)
i can go line line fixing indentation code kind of big. appreciate comment.
i've gone through similar process of trying fortran indenting work in vim. still don't have great, i've made progress. script arutaku posted (http://www.vim.org/scripts/script.php?script_id=2299) started, need create sure filetype plugin indent on
in vimrc.
i needed script determining if using fixed-form or free-form syntax, since in environment utilize both. recommended in documentation (http://vimdoc.sourceforge.net/htmldoc/syntax.html#ft-fortran-syntax). specifies, set script in ~/.vim/ftplugin/fortran.vim
:
let s:extfname = expand("%:e") if s:extfname ==? "f90" allow fortran_free_source=1 unlet! fortran_fixed_source else allow fortran_fixed_source=1 unlet! fortran_free_source endif
i utilize script can press f7 automatically finish constructs: http://www.vim.org/scripts/script.php?script_id=2487. set in ~/.vim/ftplugin/
.
i have these in vimrc seek improve things further:
let fortran_do_enddo=1 allow fortran_more_precise=1 allow fortran_have_tabs=1
i believe supposed interact first script command behavior, i'm not convinced work me. know first supposed indent do
/enddo
blocks. issue there since old-style fortran allows do
without matching enddo
, script can't indent them unless can guarantee won't utilize unmatched 'do' statements. let fortran_do_enddo=1
supposed guarantee, doesn't seem work me. lastly 1 supposed allow usage of tab character, old fortran considered bad, prevents them beingness marked errors. 1 appears work me. , honest, don't remember middle 1 supposed nor if works me.
edit:
i discovered there older version of the first script in vim installation directory (/usr/share/vim/vim70/indent/
in case) not have access rights. might have rights, , if it's causing problems, overwrite or delete it. if, me, can't edit it, can version in $home overwrite functions first. did doing 2 things. first had remove checks see if functions exist (the statements if exists("*fortrangetfixedindent")
) , had alter function declarations forcefulness overwriting using !
character, i.e. function! sebufortrangetfreeindent()
. far can tell, works expect!
vim fortran fortran90
No comments:
Post a Comment