File: c.vim

package info (click to toggle)
vim-rt 5.3-12
  • links: PTS
  • area: main
  • in suites: slink
  • size: 3,172 kB
  • ctags: 815
  • sloc: makefile: 857; awk: 778; ansic: 379; perl: 192; sh: 167
file content (145 lines) | stat: -rw-r--r-- 5,785 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
" Vim syntax file
" Language:	C
" Maintainer:	Bram Moolenaar <Bram@vim.org>
" Last change:	1998 Aug 13

" Remove any old syntax stuff hanging around
syn clear

" A bunch of useful C keywords
syn keyword	cStatement	goto break return continue asm
syn keyword	cLabel		case default
syn keyword	cConditional	if else switch
syn keyword	cRepeat		while for do

syn keyword	cTodo		contained TODO FIXME XXX

" String and Character constants
" Highlight special characters (those which have a backslash) differently
syn match	cSpecial	contained "\\x\x\+\|\\\o\{1,3\}\|\\.\|\\$"
syn region	cString		start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial
syn match	cCharacter	"'[^\\]'"
syn match	cSpecialCharacter "'\\.'"
syn match	cSpecialCharacter "'\\\o\{1,3\}'"

"when wanted, highlight trailing white space
if exists("c_space_errors")
  syn match	cSpaceError	"\s*$"
  syn match	cSpaceError	" \+\t"me=e-1
endif

"catch errors caused by wrong parenthesis
syn cluster	cParenGroup	contains=cParenError,cIncluded,cSpecial,cTodo,cUserCont,cUserLabel,cBitField
syn region	cParen		transparent start='(' end=')' contains=ALLBUT,@cParenGroup
syn match	cParenError	")"
syn match	cInParen	contained "[{}]"

"integer number, or floating point number without a dot and with "f".
syn case ignore
syn match	cNumber		"\<\d\+\(u\=l\=\|lu\|f\)\>"
"floating point number, with dot, optional exponent
syn match	cFloat		"\<\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\=\>"
"floating point number, starting with a dot, optional exponent
syn match	cFloat		"\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>"
"floating point number, without dot, with exponent
syn match	cFloat		"\<\d\+e[-+]\=\d\+[fl]\=\>"
"hex number
syn match	cNumber		"\<0x\x\+\(u\=l\=\|lu\)\>"
"syn match cIdentifier	"\<[a-z_][a-z0-9_]*\>"
syn case match
" flag an octal number with wrong digits
syn match	cOctalError	"\<0\o*[89]"

if exists("c_comment_strings")
  " A comment can contain cString, cCharacter and cNumber.
  " But a "*/" inside a cString in a cComment DOES end the comment!  So we
  " need to use a special type of cString: cCommentString, which also ends on
  " "*/", and sees a "*" at the start of the line as comment again.
  " Unfortunately this doesn't very well work for // type of comments :-(
  syntax match	cCommentSkip	contained "^\s*\*\($\|\s\+\)"
  syntax region cCommentString	contained start=+"+ skip=+\\\\\|\\"+ end=+"+ end=+\*/+me=s-1 contains=cSpecial,cCommentSkip
  syntax region cComment2String	contained start=+"+ skip=+\\\\\|\\"+ end=+"+ end="$" contains=cSpecial
  syntax region cComment	start="/\*" end="\*/" contains=cTodo,cCommentString,cCharacter,cNumber,cFloat,cSpaceError
  syntax match  cComment	"//.*" contains=cTodo,cComment2String,cCharacter,cNumber,cSpaceError
else
  syn region	cComment	start="/\*" end="\*/" contains=cTodo,cSpaceError
  syn match	cComment	"//.*" contains=cTodo,cSpaceError
endif
syntax match	cCommentError	"\*/"

syn keyword	cOperator	sizeof
syn keyword	cType		int long short char void size_t
syn keyword	cType		signed unsigned float double
syn keyword	cStructure	struct union enum typedef
syn keyword	cStorageClass	static register auto volatile extern const

syn region	cPreCondit	start="^\s*#\s*\(if\>\|ifdef\>\|ifndef\>\|elif\>\|else\>\|endif\>\)" skip="\\$" end="$" contains=cComment,cString,cCharacter,cNumber,cCommentError,cSpaceError
syn region	cIncluded	contained start=+"+ skip=+\\\\\|\\"+ end=+"+
syn match	cIncluded	contained "<[^>]*>"
syn match	cInclude	"^\s*#\s*include\>\s*["<]" contains=cIncluded
"syn match cLineSkip	"\\$"
syn cluster	cPreProcGroup	contains=cPreCondit,cIncluded,cInclude,cDefine,cInParen,cUserLabel
syn region	cDefine		start="^\s*#\s*\(define\>\|undef\>\)" skip="\\$" end="$" contains=ALLBUT,@cPreProcGroup
syn region	cPreProc	start="^\s*#\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" contains=ALLBUT,@cPreProcGroup

" Highlight User Labels
syn cluster	cMultiGroup	contains=cIncluded,cSpecial,cTodo,cUserCont,cUserLabel,cBitField
syn region	cMulti		transparent start='?' end=':' contains=ALLBUT,@cMultiGroup
" Avoid matching foo::bar() in C++ by requiring that the next char is not ':'
syn match	cUserCont	"^\s*\I\i*\s*:$" contains=cUserLabel
syn match	cUserCont	";\s*\I\i*\s*:$" contains=cUserLabel
syn match	cUserCont	"^\s*\I\i*\s*:[^:]"me=e-1 contains=cUserLabel
syn match	cUserCont	";\s*\I\i*\s*:[^:]"me=e-1 contains=cUserLabel

syn match	cUserLabel	"\I\i*" contained

" Avoid recognizing most bitfields as labels
syn match	cBitField	"^\s*\I\i*\s*:\s*[1-9]"me=e-1
syn match	cBitField	";\s*\I\i*\s*:\s*[1-9]"me=e-1

if !exists("c_minlines")
  let c_minlines = 15
endif
exec "syn sync ccomment cComment minlines=" . c_minlines

if !exists("did_c_syntax_inits")
  let did_c_syntax_inits = 1
  " The default methods for highlighting.  Can be overridden later
  hi link cLabel	Label
  hi link cUserLabel	Label
  hi link cConditional	Conditional
  hi link cRepeat	Repeat
  hi link cCharacter	Character
  hi link cSpecialCharacter cSpecial
  hi link cNumber	Number
  hi link cFloat	Float
  hi link cOctalError	cError
  hi link cParenError	cError
  hi link cInParen	cError
  hi link cCommentError	cError
  hi link cSpaceError	cError
  hi link cOperator	Operator
  hi link cStructure	Structure
  hi link cStorageClass	StorageClass
  hi link cInclude	Include
  hi link cPreProc	PreProc
  hi link cDefine	Macro
  hi link cIncluded	cString
  hi link cError	Error
  hi link cStatement	Statement
  hi link cPreCondit	PreCondit
  hi link cType		Type
  hi link cCommentError	cError
  hi link cCommentString cString
  hi link cComment2String cString
  hi link cCommentSkip	cComment
  hi link cString	String
  hi link cComment	Comment
  hi link cSpecial	SpecialChar
  hi link cTodo		Todo
  "hi link cIdentifier	Identifier
endif

let b:current_syntax = "c"

" vim: ts=8