I'm trying to write a vim syntax file for SVN dump files. The part I can't figure out is the section like this:

Fooprop: Val1
Text-content-length: 20
Barprop: Val2
                                       <- Blank line

Next-item-prop: Val3

How do I set up a syntax rule that says "N characters after the first blank line following 'Text-content-length: N' where N is a number"?

  • Vim has no generic concept of that. Vim can highlight keywords, patterns and stuff between two patterns. You are aiming for context sensitive highlighting rules, for patterns that adapt when matching. I never hacked vim, but theoretically you can get what you want by making vim first parse the file, then create specialized highlighting rules from a template and finally have vim use the specialized rules.
    – Bananguin
    Commented May 10, 2013 at 19:34

1 Answer 1


You would need to reference the text length in a different regular expression. Because Vim (unlike Perl) doesn't allow the evaluation of Vimscript expressions inside regular expressions, you need to resort to meta programming, i.e. build the syntax rules on the fly:

:execute 'syntax match svndumpData /^\n\_.\{' . length . '}/'

This simple sketch uses \_. to match any character (including newlines) for \{N} times. You need to be careful about the length of the newline (CR-LF vs. LF) and encodings (number of characters is not necessarily equal to the number of bytes to represent them!)

This works because a syntax plugin is sourced on each detection, and the syntax then applies to the current buffer.


Since this is rather complex, and may not work if you have a byte count (for which no regular expression atom exists) instead of character length, there's always the pragmatic 80% solution that ignores the contained character count and just defines the syntax region on the surrounding property sections. It won't be correct in all cases, but probably works well for most data.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .