Example:
%YAML 1.2
---
name: Fixed width test
scope: source.test.fixed-width
contexts:
main:
- match: '^(FEAT)'
captures:
1: storage
push:
- string-30
- space
- code-6
- space
- int-8
- space
- string-35
- space
- int-8
- space
pop-on-eol:
- match: $
pop: true
space:
- include: pop-on-eol
- match: ' '
scope: punctuation.separator.field.fixed-width
pop: true
- match: .
scope: invalid.illegal.fixed-width
pop: true
int-8:
- include: pop-on-eol
- match: (?=(\d+)\s*(.*)).{8}
captures:
1: constant.numeric.fixed-width
2: invalid.illegal.fixed-width
pop: true
string-35:
- include: pop-on-eol
- match: .{35}
scope: string.unquoted.fixed-width
pop: true
string-30:
- include: pop-on-eol
- match: .{30}
scope: string.unquoted.fixed-width
pop: true
code-6:
- include: pop-on-eol
- match: (?=(WB|UI)?\s*(.*)).{6}
captures:
1: constant.other.fixed-width
2: invalid.illegal.fixed-width
pop: true
This will highlight FEAT lines.
Some explanation of the regex (?=(\d+)\s*(.*)).{8}
may be in order. The regex consists of an unbounded lookahead with captures followed by a bounded “main” part. The total length of the match will be 8 characters exactly, but the lookahead may look well beyond that. However, even if the lookahead captures match more than 8 characters, Sublime will only highlight the first 8. This lets you use the .{8}
part to set the length of the match while using lookaheads to capture variable-length parts of the match.
If you have questions about the above syntax, please ask; it’s a bit unorthodox.