I have a code written in Fortran 77 and I read it with vim. The code is written such that the comments are on lines starting with c, as is standard in Fortran 77. However, vim does not recognize them and therefore use a coloring syntax that makes the code very difficult to read! How can I overcome this?
I've seen that there is a post with the same problem. I have read the answers and tried the different solutions that have been suggested:
add let fortran_have_tabs=1 to .vimrc
add
syn match fortranComment excludenl "^[!c*].*$" contains=@fortranCommentGroup,@spell
syn match fortranComment excludenl "!.*$" contains=@fortranCommentGroup,@spell
to .vimrc
but they do not work for me. Does someone know why? Have I made a mistake somewhere? Otherwise, does anyone have a different suggestion?
This is what works for me in my .vimrc:
let fortran_have_tabs=1
if has('syntax') && (&t_Co > 2)
syntax enable
endif
The important part is most likely the syntax enable part. You may also need this:
filetype on
Also try typing in :help ft-fortran-syntax and reading that (or see here: http://vimdoc.sourceforge.net/htmldoc/syntax.html#ft-fortran-syntax). What I took away from that was that I needed to create the file ~/.vim/ftplugin/fortran.vim and put this in it:
let s:extfname = expand("%:e")
if s:extfname ==? "f90"
let fortran_free_source=1
unlet! fortran_fixed_source
else
let fortran_fixed_source=1
unlet! fortran_free_source
endif
And also put this in your .vimrc:
filetype plugin indent on
That does the trick for me so that I can view and edit free-form and fixed-form with no problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With