Vim uses regular expressions for syntax highlighting. Often maintaining these can become rather unwieldy. For example:

syn match goVarAssign /\v[_.[:alnum:]]+(,\s*[_.[:alnum:]]+)*\ze(\s*([-^+|^\/%&]|\*|\<\<|\>\>|\&\^)?\=[^=])/

For example Python supports comments inside regular expressions, which would make things a lot more helpful:

syn match goVarAssign /\v
    [_.[:alnum:]]+          " One or more valid identifier characters.
    (,\s*[_.[:alnum:]]+)*   " Repeated one or more times separated by ,
    \ze                     " Start matching here
      \s*                   " Any whitespace
      (                     " ... um?
      ?\=[^=]               " .. um?

The above pseudo-example does not work, but is there any way to approach something like that in Vim?

  • Maybe an option would be to build the command in a string variable (it is then possible to comment each part of the string) and then use execute() on the built string? That's clearly not as good as python but I'm not sure there are better option. – statox Apr 8 '18 at 16:05

Your Answer

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

Browse other questions tagged or ask your own question.