While you could use a regular expression to identify such lines with a specific number of characters, e.g. \v^%(.){6}\n%(\=){6}
, there's no way to do so for an arbitrary number of characters with Vim regexes.1
Hopefully you'll be able to use a Vimscript solution. For example this one liner will save the line numbers of all line pairs that match your criteria:
g/^[=]\+$/ if strlen(getline(line(".") - 1)) == strlen(getline(".")) | call add(b:matches, line(".") - 1) | endif
It requires existence of a list b:matches
.
This one is a little easier to read and initializes the list and prints its contents...
let b:matchlines = []
g/^[=]\+$/ if strlen(getline(line(".") - 1)) == strlen(getline("."))
call add(b:matches, line(".") - 1)
endif
echo b:matchlines
Should be easy to tweak this as needed (e.g. if you wanted to save the actual matched text instead of line numbers). If you need some help with such a change let me know.
1 For those hungry for some red meat here's @perelo's comment on why this is so... Actually this is a well-known limitation of theoretical regular expressions. Although pattern matching engines allow more expressivity than th. R.E. (e.g. backreferences with (...)), they cannot match strings as a^nb^n for any n. In your case, 'a' is like . and 'b' is =. Intuitivelly, R.E. are like DFA, so they cannot count dynamically. Patterns such as {n} are obtained by adding O(n) states to the corresponding DFA. This is why we cannot syntactically check a program with a single regex : matching parentheses are like (^n )^n.
g
=
s, and at least 3 or 4 of them." That's most likely what the Setex parsers do anyways (I don't think they'll check for the same length.) If you're using this for syntax, it might be awkward if you edit the heading and it will only highlight it back when you adjust the following line with the=
s...