Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax highlighting of Fortran 77 comments not working in vim

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:

  1. add let fortran_have_tabs=1 to .vimrc

  2. 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?

like image 908
Angelo Sajeva Avatar asked Oct 23 '22 13:10

Angelo Sajeva


1 Answers

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.

like image 149
pattivacek Avatar answered Nov 04 '22 01:11

pattivacek