David Ben Knoble has already given you a good, working solution.
However, seeing as this is syntax that you're highlighting, I feel like it's cleaner to perform the task with a :syntax
command. This also has the slight advantage that :match
is free for other purposes.
For reasons I'm slightly unclear on, it's not possible to use the previously explained \zs
atom in this match, but it's easy to achieve using a syntax pattern offset instead. Drop the following command in the file ~/.vim/after/syntax/go.vim
:
syntax match goExportedFunction /func [A-Z][a-z0-9_]*/hs=s+5 contains=goDeclaration
highlight default link goExportedFunction Title
This syntax group will take precedence over the existing goDeclaration
group used for the func
because it starts in the same position, but was declared later.
The hs=s+5
after the regular expression tells Vim that you want the highlighting to start 5 characters after the beginning of the match i.e. at the start of the function name.
The contains=goDeclaration
might not strictly be necessary depending on your colour scheme, but it means that the func
at the beginning of the line is still matched by the goDeclaration
group in the same way as before.
N.B. For clarity, I've used the same basic regular expression as you used. However, as I suggested in a comment, the following is faster, more concise, and more correct:
syntax match goExportedFunction /func \u\w*/hs=s+5 contains=goDeclaration
Further Reading
:help :syn-priority
:help :syn-pattern-offset
:help :syn-contains
match Title /func \zs[A-Z][a-z0-9_]*/
– Christian Brabandt Oct 25 '17 at 10:23/func [A-Z][A-Za-z0-9_]*
? This can then be written more concisely as/func \u\w*/
– Rich Oct 27 '17 at 14:29