說明:判斷是否類型的簡單辦法,就是簡單的觀察:如果該標誌符後面有空格,空格後又是一個標誌符的話,在C/C++語言中,可以肯定這一定是一個類型了。所以用Regex判斷就可以了。
經過測試,該文法定義幾乎能完美的工作。包括在template下,以及 < > 中,以及函數定義中,引用什麼的。喜歡的朋友可以複製過來用哦!
缺點:沒有進行文法分析,只是基於上述簡單的邏輯來實現的,存在著紕漏,但是目前測試還沒遇到。以後的解決方向,寫vim指令碼判斷typedef 出來的自訂類型,然後加入到syntax keyword列表。我覺得這才是正道。
不過,在這個搞出來之前,下面這個也夠用了:-)
1
"========================================================
2
" Highlight All Math Operator
3
"========================================================
4
" C math operators
5
syn
match
cMathOperator display
"
[-+*/%=]
"
6
" C pointer operators
7
syn
match
cPointerOperator display
"->
/|
/."
8
" C logical operators - boolean results
9
syn
match
cLogicalOperator display
"
[!<>]
=/="
10
syn
match
cLogicalOperator display
"=="
11
" C bit operators
12
syn
match
cBinaryOperator display
"
/(
&
/|
|
/|
/^
/|
<<
/|
>>
/)
=/="
13
syn
match
cBinaryOperator display
"/~"
14
syn
match
cBinaryOperatorError display
"/~="
15
" More C logical operators - highlight in preference to binary
16
syn
match
cLogicalOperator display
"&&
/|
||"
17
syn
match
cLogicalOperatorError display
"
/(
&&
/|
||
/)
="
18
" Math Operator
19
hi
def link
cMathOperator cOperator
20
hi
def link
cPointerOperator cOperator
21
hi
def link
cLogicalOperator cOperator
22
hi
def link
cBinaryOperator cOperator
23
hi
def link
cLogicalOperator cOperator
24
25
hi
cOperator guifg
=#3EFFE2
26
hi
def link
cBinaryOperatorError Error
27
hi
def link
cLogicalOperatorError Error
28
"========================================================
29
" Highlight typedef types ( include cpp syntax... )
30
" =======================================================
31
syn
match
cTypeDefType "/</I/i*/>
/(
&/=/s*/*/=/s*&/=/I
/)
/@="
32
syn
match
cTypeDefType "/</I/i*::/i*
/(
&/=/s*/*/=/s*&/=/I
/)
/@="
contains=
cScope,cFunction
33
syn
match
cTypeDefType "/</I
/(
/i*</s*/I/i*/s*>::
/)
/+/i*
/(
&/=/s*/*/=/s*&/=/I
/)
/@="
contains=
cScope,cFunction,cTypeDefTypeTwo
34
syn
match
cTypeDefTypeTwo "</s*/I/i*/s*>"
contains=
cLogicalOperator
35
36
hi
cTypeDefType guifg
=#c0d8f8
37
hi
cTypeDefTypeTwo guifg
=#c0d8f8
38
" Highlight ;
39
syn
match
sColon display
/;/
40
syn
match
cScope display
/::/
41
hi
cScope guifg
=#3EFFE2
42
hi
sColon guifg
=#60d080
43
"========================================================
44
" Highlight All Function
45
"========================================================
46
syn
match
cFunction "
[a-zA-Z_][a-zA-Z_0-9]
*/s*("
me=e-1
47
syn
match
cFunction "/<
[a-zA-Z_][a-zA-Z_0-9]
*/>/s*("
me=e-1
48
syn
match
cFunction "/<
[a-zA-Z_][a-zA-Z_0-9]
*
/(
</I/i*>/s*(
/)
/@="
49
hi
cFunction gui
=NONE
guifg
=#B5A1FF