2

I am trying to write a VIM highlight file for Gaussian 09 inputs. One example of "control" line is shown below:

# P TPSSTPSS 6-31G* DENSITYFIT
  OPT(VERYTIGHT) INT(ULTRAFINE)
  FREQ(NORAMAN)

TITLE LINE, NOT CONTROL LINE, SO OPT HERE SHOULD NOT HIGHLIGHT

The point is, if a # mark is found at the beginning of the line, then the following lines are concatenated until an empty line is found, and the words are considered as keywords, e.g. OPT is a keyword in the second row, however it is no longer a keyword in the fifth row.

How do I let the syntax command in VIM know it needs to join them, and restrict the keywords inside it?

1

You can do this with a syntax region. Basically you have to define that your keywords will be contained in a region and then define the region that they will be contained in. Like so:

syn keyword ConcatKeywords OPT INT FREQ contained
syn region Concat start='^#' end='^$' contains=ConcatKeywords

The important part here is the contained option after the first line and the contains= option after the second line. This will make vim look for these keywords only in the regions that have it contained.

You will, of course, then need to highlight your keywords. You can define your own or link it to an already exsisting highlight:

hi link ConcatKeywords PreProc

For more info I would recommend this great tutorial on the vim wiki, as well as these help documents: :h syn-keyword, :h syn-match, and :h syn-region

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.