4

I am trying to highlight my own class name and function name in C++ via GVim. I read and followed the link from stackoverflow. Please also check out the result link

I copied the following settting in my cpp.vim where is under syntax directory.

" Highlight Class and Function names 
syn match    cCustomParen    "(" contains=cParen,cCppParen 
syn match    cCustomFunc     "\w\+\s*(" contains=cCustomParen
syn match    cCustomScope    "::"
syn match    cCustomClass    "\w\+\s*::" contains=cCustomScope
hi def link cCustomFunc  Function
hi def link cCustomClass Function 

It worked, but highlight my brackets in red. How do I disable the highlight of the brackets? I deleted .vimrc file and open my cpp file again, it's still same. So I think it's the above code issue.

-------------------- Resolved [Solution] --------------------

syn match   customFunc "\<[a-zA-Z_][a-zA-Z_0-9]*\>[^()]*)("me=e-2
syn match   customFunc "\<[a-zA-Z_][a-zA-Z_0-9]*\>\s*("me=e-1
hi def customFunc   gui=NONE guifg=#E54023   
syn match    cCustomScope    "::"
syn match    cCustomClass    "\w\+\s*::" contains=cCustomScope
hi def link cCustomClass Function 

--------------------------- EOF ------------------------------

enter image description here

Community
  • 1
  • 1
CCC
  • 2,164
  • 8
  • 27
  • 47

2 Answers2

3

You should edit your .vimrc file. Simply add this line to the file:

let g:loaded_matchparen= 1
ib.
  • 27,830
  • 11
  • 80
  • 100
Gergely Bacso
  • 14,243
  • 2
  • 44
  • 64
0

You didn't introduce the mathcing brakcets with your changes. It's vim default behaviour. So, just add

let g:loaded_matchparen= 1 

to your .vimrc file.

Marco
  • 2,190
  • 15
  • 22
  • @sav, it's still same. I think it's the problem of the code, coz after I remove the code, it doesn't have the problem. – CCC Jun 30 '11 at 10:05
  • is: enter code here`syn match cCustomFunc "\w\+\s*(" contains=cCustomParen、just a copy and paste issue here in stackoverflow ? or is this really in your vimrc ? doesn't this cause issues ? – Marco Jun 30 '11 at 10:17
  • @sav, yes, I just copy the code and save into my cpp.vim file, not .vimrc file. Before I add the code I haven't had the issue. – CCC Jun 30 '11 at 10:23
  • please make sure that second line: "enter code here" which is in your example above and NOT in the original post is only a copy&paste issue here, and NOT in your vimrc file :-) – Marco Jun 30 '11 at 10:33
  • @sav, ;-) right, not in my code, I changed in the post. I am sure my code is correct. – CCC Jun 30 '11 at 10:41
  • @sav, I think it's the Line2 and Line3 issue. coz for the class name, it works. Anyway, I used other pattern to solve it. – CCC Jun 30 '11 at 10:44