使用Vim打造IDE--高亮顯示
在~/.vim/syntax/ 下建立c.vim。如果沒有該目錄,則請自己建立。
Vim會使用該指令碼,讀入文法高亮的規則,編輯c.vim檔案如下:
"========================================================
" Highlight All Function
"========================================================
syn match cFunction "/<[a-zA-Z_][a-zA-Z_0-9]*/>[^()]*)("me=e-2
syn match cFunction "/<[a-zA-Z_][a-zA-Z_0-9]*/>/s*("me=e-1
hi cFunction gui=NONE guifg=#B5A1FF
"========================================================
" Highlight All Math Operator
"========================================================
" C math operators
syn match cMathOperator display "[-+/*/%=]"
" C pointer operators
syn match cPointerOperator display "->/|/."
" C logical operators - boolean results
syn match cLogicalOperator display "[!<>]=/="
syn match cLogicalOperator display "=="
" C bit operators
syn match cBinaryOperator display "/(&/||/|/^/|<</|>>/)=/="
syn match cBinaryOperator display "/~"
syn match cBinaryOperatorError display "/~="
" More C logical operators - highlight in preference to binary
syn match cLogicalOperator display "&&/|||"
syn match cLogicalOperatorError display "/(&&/|||/)="
" Math Operator
hi cMathOperator guifg=#3EFFE2
hi cPointerOperator guifg=#3EFFE2
hi cLogicalOperator guifg=#3EFFE2
hi cBinaryOperator guifg=#3EFFE2
hi cBinaryOperatorError guifg=#3EFFE2
hi cLogicalOperator guifg=#3EFFE2
hi cLogicalOperatorError guifg=#3EFFE2
"========================================================
" My Own DataType
"========================================================
syn keyword cType My_Type_1 My_Type_2 My_Type_3
上述最後的是對於自己定義的資料類型進行高亮顯示。這樣對於My_Type_1 My_Type_2 My_Type_3都變得高亮了。
使用Vim打造IDE--高亮顯示