我使用不使用linkbreaks的FITS文件。 以下是一个此类文件的片段:
SIMPLE = T / file does conform to FITS standard BITPIX = 8 / number of bits per data pixel NAXIS = 0 / number of data axes EXTEND = T / FITS dataset may contain extensions COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H TELESCOP= 'TELESCOP' / Telescope (mission) name INSTRUME= 'INST ' / Instrument name OBS_ID = '00000000000' / Observation ID TARG_ID = 00000 / Target ID SEG_NUM = 0 / Segment number TIMESYS = 'TT ' / time measured from
当我查看这些文件时,我使用set numberwidth=6
和set columns=86
SIMPLE = T / file does conform to FITS standard
BITPIX = 8 / number of bits per data pixel
NAXIS = 0 / number of data axes
EXTEND = T / FITS dataset may contain extensions
COMMENT FITS (Flexible Image Transport System) format is defined in 'Astronomy
COMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H
TELESCOP= 'TELESCOP' / Telescope (mission) name
INSTRUME= 'INST ' / Instrument name
OBS_ID = '00000000000' / Observation ID
TARG_ID = 00000 / Target ID
SEG_NUM = 0 / Segment number
TIMESYS = 'TT ' / time measured from
问题是syntax match myComment " / .*$"
显然不尊重set columns
,它会突出显示第一条评论后的所有内容。我希望它知道第一条评论只能扩展到第80列,第二条评论在第160列结束,依此类推。
我已经创建了一个vim语法文件:
if exists("b:current_syntax")
finish
endif
syn match fitsComment1 " / .*\%80c"
hi link fitsComment1 Comment
syn match fitsComment2 "COMMENT.*\%400c"
hi link fitsComment2 Comment
syn match fitsComment2 "COMMENT.*\%480c"
hi link fitsComment2 Comment
let c1 = 80
let c2 = 160
let c = 1
while c <= 8
let regex = '" \%>' . c1 . 'c/ .*\%' . c2 . 'c"'
execute 'syn match fitsComment2 '.regex
hi link fitsComment2 Comment
let c1 += 80
let c2 += 80
let c += 1
endwhile
let b:current_syntax = "fits"
此文件产生所需的突出显示,但有一些警告:
“多行”评论以COMMENT
开头。
我添加了
syn match fitsComment2 "COMMENT.*\%400c"
hi link fitsComment2 Comment
syn match fitsComment2 "COMMENT.*\%480c"
hi link fitsComment2 Comment
在我的示例中明确处理它们,但它不是真正的修复,因为我并不总是知道这些多行注释将在何处发生。
有没有办法可以在没有while
循环的情况下执行此操作?循环使得读取文件的速度非常慢(这些文件可能会很长)。
答案 0 :(得分:0)
你可以这样做:
syn match myComment1 " / .*\%80c"
syn match myComment2 " \%>80c/ .*\%180c"
hi link myComment1 Comment
hi link myComment2 Comment
这使用\%c
正则表达式原子将正则表达式锚定到特定列。您必须创建新的syn匹配规则,直到覆盖所需的所有列。注意,第二个注释规则明确地锚定在第80列之后开始,否则它将从第一个注释char到最后一个(贪婪匹配)。