Syntax highlighting of Fortran 77 comments not working in vim

可紊 提交于 2019-12-10 14:05:48

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/11903166/syntax-highlighting-of-fortran-77-comments-not-working-in-vim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!