This is hard to read, but given something like:
(a)*(b)(c)*
And input like:
aaaaaabccccc
Vim is going to capture only the last "a" matched by "(a)*".
To make it capture the whole thing we need to turn:
(a)*
into:
(%(a)*)
ie. make the inner "(a)" non-capturing.
With Vim's unfortunate escaping, these examples get a bit uglier:
\(\%(a\)*\)
instead of:
(%(a)*)
and so on...
This fixes the issue we had where a group like `Underlined`:
term=underline cterm=underline ctermfg=1 gui=underline guifg=#cc6666
was being emboldened incorrectly as:
cterm=bold ctermfg=1 gui=bold,underline guifg=#cc6666
Because the following sequence would occur:
1. Search for "gui=...", identifying "ctermfg=..." as the prefix and
"guifg=..." as the suffix.
2. Throw away "cterm=bold" while reconstructing the new highlight,
because it was not correctly captured.
3. etc... all bets are off here because we've already thrown away data.
" Check for existing setting.
let l:matches = matchlist(
\ l:original,
- \ '^\([^ ]\+ \)*' .
+ \ '^\(\%([^ ]\+ \)*\)' .
\ '\(' . l:lhs . '=[^ ]\+\)' .
- \ '\( .\+\)*$'
+ \ '\(\%( [^ ]\+\)*\)$'
\ )
if l:matches == []
" No setting, add one with just a:style in it