fortran_free_source interrupts comment syntax coloring in vim

。_饼干妹妹 提交于 2019-12-23 04:33:38

问题


I am reading fortran 77 code (which I hate!) and in order to keep vim from coloring the lines weirdly after line 72, I included let fortran_free_source=1 before the syntax on line in my .vimrc.

However, after doing this, all comments which begin with 'C' or 'c' are not colored the way comments should be colored. Only comments which begin with '!' are colored correctly. How should I edit my .vimrc file so that comments in the old fortran style are colored correctly?


回答1:


New answer: Add to your .vimrc let fortran_have_tabs=1 that should get rid of it. The only side effect will be that tabs are no longer highlighted.

Old answer:

I wouldn't know any direct solution for this but a dirty hack would be to copy the fortran.vim in your syntax folder and remove line 332:

    syn match fortranSerialNumber       excludenl "^.\{73,}$"lc=72

if you call it myfortran.vim (in your ~/.vim/syntax folder) you can use set syntax=myfortran. I'm sure there must be a more elegant way but this should work.

If you leave it as fortran.vim then only the file in ~/.vim/syntax will be loaded and not the one in /usr/yourvimdir/




回答2:


You're solving your problem in a wrong way. Vim colors the past the 72th column for a reason, for that is invalid code, to show you it would be ignored.

Anyways, since I don't know what it is coloring from your description, so I'll guess it is a string, try

hi! link fortranSerialNumber fortranString

and let us know the results...




回答3:


Put this in ~/.vimrc/after/syntax/fortran.vim:

syn match fortranComment excludenl "^[!c*].*$" contains=@fortranCommentGroup,@spell
syn match fortranComment excludenl "!.*$" contains=@fortranCommentGroup,@spell

This highlights all types of Fortran comments, regardless of other highlighting options like fixed or free source form.

Anything in ~/.vimrc/after/syntax/ runs after parsing the default syntax highlighting file. The two lines above are in my copy of fortran.vim, but are inside of if statements so they don't always take effect.

You could add a d inside the first line "^[!cd*].*$" if you want to highlight the non-standard "d" comment lines.



来源:https://stackoverflow.com/questions/9505125/fortran-free-source-interrupts-comment-syntax-coloring-in-vim

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