abstract
| - The following ruby script generates a pattern (see below) used for highlighting a codesection from the curly brace under the cursor to the matching brace. It currently finds 12 recursions, you can generate larger patterns reaching deeper by changing the parameter (n=12) in method "generate". # ruby script def next_iteration(text) text.gsub( /#{Regexp.quote("a%(x)*b")}/, "a%(%(a%(x)*b)|%(x))*b" ) end def generate( text, n ) 1.upto(n){ |i| text = next_iteration( text ) } text end def to_pattern(text) text.gsub(/x/,"\
|[^ab]").gsub(/a/,"\\{").gsub(/b/,"\\}") end ax = generate("a%(x)*b", 12).sub(/b$/,"") # a = starting brace, b = ending brace, x = characters in between puts to_pattern( "/\\v%(%##{ax}b)|%(#{ax}%#b)/" ) "a" and "b" are synonyms for the starting/ending brace, "x" holds the characters in between, if any. Using recursion, the original pattern "a(x)*b" is expanded to the monstrous pattern seen below. Note: Use %() for grouping in the pattern, as the normal (captivating) variant cannot be used that often in one pattern. Append the following to your vimrc: highlight ShowMatches guibg=darkgrey guifg=white au! Cursorhold * exe 'match ShowMatches /\v%(%#\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(
|[^\{\}])*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(%(\{%(
|[^\{\}])*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*\})|%(
|[^\{\}]))*%#\})/' set ut=30 Up to now, creating a pattern for mixing curly braces and brackets hasn't been very successful. The resulting patterns grow far too fast.
|