@@ -1622,12 +1622,30 @@ fu! s:highlight(pat, grp)
16221622 if s: matcher != {} | retu | en
16231623 cal clearmatches ()
16241624 if ! empty (a: pat ) && s: ispath
1625- let pat = s: regexp ? substitute (a: pat , ' \\\@<!\^' , ' ^> \\zs' , ' g' ) : a: pat
1626- if s: byfname
1627- let pat = substitute (pat, ' \[\^\(.\{-}\)\]\\{-}' , ' [^\\/\1]\\{-}' , ' g' )
1628- let pat = substitute (pat, ' \$\@<!$' , ' \\ze[^\\/]*$' , ' g' )
1625+ if s: regexp
1626+ let pat = substitute (a: pat , ' \\\@<!\^' , ' ^> \\zs' , ' g' )
1627+ cal matchadd (a: grp , ( s: martcs == ' ' ? ' \c' : ' \C' ).pat)
1628+ el
1629+ let pat = a: pat
1630+
1631+ " calculate how many letters are here
1632+ let lettercount = len (split (pat, ' \\{-}' ))
1633+ for i in range (lettercount)
1634+ " surround the letter we care about with \zs and \ze so only it is
1635+ " highlighted in this go.
1636+ let letterpat = substitute (pat, ' ^\%(.\{-}\\{-}\)\{' .i .' }\zs.\{-}\ze\%(\[^.*\)\?$' , ' \\zs\0\\ze' , ' ' )
1637+
1638+ if s: byfname
1639+ " replace [^x] with [^/x] to make sure no slashes between letters
1640+ let letterpat = substitute (letterpat, ' \[\^\(.\{-}\)\]\\{-}' , ' [^\\/\1]\\{-}' , ' g' )
1641+ " replace the end to make sure no slashes follow the pattern
1642+ let letterpat = substitute (letterpat, ' \$\@<!$' , ' [^\\/]*$' , ' g' )
1643+ en
1644+
1645+ cal matchadd (a: grp , ( s: martcs == ' ' ? ' \c' : ' \C' ).letterpat)
1646+ endfo
16291647 en
1630- cal matchadd ( a: grp , ( s: martcs == ' ' ? ' \c ' : ' \C ' ).pat)
1648+
16311649 cal matchadd (' CtrlPLinePre' , ' ^>' )
16321650 en
16331651endf
0 commit comments