Vim syntax highlighting-a simple way to highlight custom types

Source: Internet
Author: User
Tags keyword list

Note: A simple method to determine whether a flag is of type is to observe it. If there is a space behind the flag and a flag behind the space, in C/C ++, it must be a type. So you can use a regular expression to determine.

After testing, the syntax definition can work almost perfectly. It is included in the template, and <>, and in the function definition. Friends you like can copy and use it!

Disadvantage: syntax analysis is not performed, but it is implemented based on the simple logic described above. There is a flaw in it, but it has not been tested yet. In the future, write the vim script to determine the custom type of typedef and add it to the syntax keyword list. I think this is the right way.

However, before this is done, the following will be enough :-)

 

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 =
Csction, 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 */s *>"
Contains =
CLogicalOperator
35

36
Hi
CTypeDefType guifg
= # C0d8f8

37
Hi
CTypeDefTypeTwo guifg
= # C0d8f8

38
"Highlight;

39
Syn
Match
SColon display
/;/

40
Syn
Match
Cs1_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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.