c.vim (35470B)
1 " Vim syntax file 2 " Language: C 3 " Maintainer: The Vim Project <https://github.com/vim/vim> 4 " Last Change: 2026 Sep 21 5 " Former Maintainer: Bram Moolenaar <Bram@vim.org> 6 7 " Quit when a (custom) syntax file was already loaded 8 if exists("b:current_syntax") 9 finish 10 endif 11 12 let s:cpo_save = &cpo 13 set cpo&vim 14 15 let s:ft = matchstr(&ft, '^\%([^.]\)\+') 16 17 " check if this was included from cpp.vim 18 let s:in_cpp_family = exists("b:filetype_in_cpp_family") 19 20 " Optional embedded Autodoc parsing 21 " To enable it add: let g:c_autodoc = 1 22 " to your .vimrc 23 if exists("c_autodoc") 24 syn include @cAutodoc <sfile>:p:h/autodoc.vim 25 unlet b:current_syntax 26 endif 27 28 " In VMS C keywords contain '$' characters. 29 if has("vms") 30 syn iskeyword @,48-57,_,192-255,$ 31 else 32 syn iskeyword @,48-57,_,192-255 33 endif 34 35 " A bunch of useful C keywords 36 syn keyword cStatement goto break return continue asm 37 syn keyword cLabel case default 38 syn keyword cConditional if else switch 39 syn keyword cRepeat while for do 40 41 syn keyword cTodo contained TODO FIXME XXX 42 43 " It's easy to accidentally add a space after a backslash that was intended 44 " for line continuation. Some compilers allow it, which makes it 45 " unpredictable and should be avoided. 46 syn match cBadContinuation contained "\\\s\+$" 47 48 " cCommentGroup allows adding matches for special things in comments 49 syn cluster cCommentGroup contains=cTodo,cBadContinuation 50 51 " String and Character constants 52 " Highlight special characters (those which have a backslash) differently 53 syn match cSpecial display contained "\\\%(x\x\+\|\o\{1,3}\|.\|$\)" 54 if !exists("c_no_utf") 55 syn match cSpecial display contained "\\\%(u\x\{4}\|U\x\{8}\)" 56 endif 57 58 if !exists("c_no_cformat") 59 " Highlight % items in strings. 60 if !exists("c_no_c99") " ISO C99 61 syn match cFormat display "%\%(\d\+\$\)\=[-+' #0*]*\%(\d*\|\*\|\*\d\+\$\)\%(\.\%(\d*\|\*\|\*\d\+\$\)\)\=\%([hlLjzt]\|ll\|hh\)\=\%([aAbdiuoxXDOUfFeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained 62 else 63 syn match cFormat display "%\%(\d\+\$\)\=[-+' #0*]*\%(\d*\|\*\|\*\d\+\$\)\%(\.\%(\d*\|\*\|\*\d\+\$\)\)\=\%([hlL]\|ll\)\=\%([bdiuoxXDOUfeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained 64 endif 65 syn match cFormat display "%%" contained 66 endif 67 68 " cCppString: same as cString, but ends at end of line 69 if s:in_cpp_family && !exists("cpp_no_cpp11") && !exists("c_no_cformat") 70 " ISO C++11 71 syn region cString start=+\%(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend 72 syn region cCppString start=+\%(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell 73 elseif s:ft ==# "c" && !exists("c_no_c11") && !exists("c_no_cformat") 74 " ISO C99 75 syn region cString start=+\%(L\|U\|u8\)\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend 76 syn region cCppString start=+\%(L\|U\|u8\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell 77 else 78 " older C or C++ 79 syn match cFormat display "%%" contained 80 syn region cString start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend 81 syn region cCppString start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell 82 endif 83 84 syn region cCppSkip contained start="^\s*\%(%:\|#\)\s*\%(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\%(%:\|#\)\s*endif\>" contains=cSpaceError,cCppSkip 85 86 syn cluster cStringGroup contains=cCppString,cCppSkip 87 88 syn match cCharacter "L\='[^\\]'" 89 syn match cCharacter "L'[^']*'" contains=cSpecial 90 if exists("c_gnu") 91 syn match cSpecialError "L\='\\[^'\"?\\abefnrtv]'" 92 syn match cSpecialCharacter "L\='\\['\"?\\abefnrtv]'" 93 else 94 syn match cSpecialError "L\='\\[^'\"?\\abfnrtv]'" 95 syn match cSpecialCharacter "L\='\\['\"?\\abfnrtv]'" 96 endif 97 syn match cSpecialCharacter display "L\='\\\o\{1,3}'" 98 syn match cSpecialCharacter display "'\\x\x\{1,2}'" 99 syn match cSpecialCharacter display "L'\\x\x\+'" 100 101 if (s:ft ==# "c" && !exists("c_no_c11")) || (s:in_cpp_family && !exists("cpp_no_cpp11")) 102 " ISO C11 or ISO C++ 11 103 if exists("c_no_cformat") 104 syn region cString start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,@Spell extend 105 else 106 syn region cString start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend 107 endif 108 syn match cCharacter "[Uu]'[^\\]'" 109 syn match cCharacter "[Uu]'[^']*'" contains=cSpecial 110 if exists("c_gnu") 111 syn match cSpecialError "[Uu]'\\[^'\"?\\abefnrtv]'" 112 syn match cSpecialCharacter "[Uu]'\\['\"?\\abefnrtv]'" 113 else 114 syn match cSpecialError "[Uu]'\\[^'\"?\\abfnrtv]'" 115 syn match cSpecialCharacter "[Uu]'\\['\"?\\abfnrtv]'" 116 endif 117 syn match cSpecialCharacter display "[Uu]'\\\o\{1,3}'" 118 syn match cSpecialCharacter display "[Uu]'\\x\x\+'" 119 endif 120 121 if (s:ft ==# "c" && !exists("c_no_c23")) || (s:in_cpp_family && !exists("cpp_no_cpp17")) 122 syn match cCharacter "u8'[^\\]'" 123 syn match cCharacter "u8'[^']*'" contains=cSpecial 124 if exists("c_gnu") 125 syn match cSpecialError "u8'\\[^'\"?\\abefnrtv]'" 126 syn match cSpecialCharacter "u8'\\['\"?\\abefnrtv]'" 127 else 128 syn match cSpecialError "u8'\\[^'\"?\\abfnrtv]'" 129 syn match cSpecialCharacter "u8'\\['\"?\\abfnrtv]'" 130 endif 131 syn match cSpecialCharacter display "u8'\\\o\{1,3}'" 132 syn match cSpecialCharacter display "u8'\\x\x\+'" 133 endif 134 135 "when wanted, highlight trailing white space 136 if exists("c_space_errors") 137 if !exists("c_no_trail_space_error") 138 syn match cSpaceError display excludenl "\s\+$" 139 endif 140 if !exists("c_no_tab_space_error") 141 syn match cSpaceError display " \+\t"me=e-1 142 endif 143 endif 144 145 " This should be before cErrInParen to avoid problems with #define ({ xxx }) 146 if exists("c_curly_error") 147 syn match cCurlyError "}" 148 syn region cBlock start="{" end="}" contains=ALLBUT,cBadBlock,cCurlyError,cInitBlock,@cParenGroup,cErrInParen,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell fold 149 else 150 syn region cBlock start="{" end="}" transparent fold 151 endif 152 153 " Catch errors caused by wrong parenthesis and brackets. 154 " Also accept <% for {, %> for }, <: for [ and :> for ] (C99) 155 " But avoid matching <::. 156 syn cluster cParenGroup contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserLabel,cBitField,cOctalZero,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cBadParenBlock 157 if exists("c_no_curly_error") 158 if s:in_cpp_family && !exists("cpp_no_cpp11") 159 syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,@cStringGroup,@Spell 160 " cCppParen: same as cParen but ends at end-of-line; used in cDefine 161 syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell 162 syn match cParenError display ")" 163 syn match cErrInParen display contained "^^<%\|^%>" 164 else 165 syn region cParen transparent start='(' end=')' contains=ALLBUT,cBlock,@cParenGroup,cCppParen,@cStringGroup,@Spell 166 " cCppParen: same as cParen but ends at end-of-line; used in cDefine 167 syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell 168 syn match cParenError display ")" 169 syn match cErrInParen display contained "^[{}]\|^<%\|^%>" 170 endif 171 elseif exists("c_no_bracket_error") 172 if s:in_cpp_family && !exists("cpp_no_cpp11") 173 syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,@cStringGroup,@Spell 174 " cCppParen: same as cParen but ends at end-of-line; used in cDefine 175 syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell 176 syn match cParenError display ")" 177 syn match cErrInParen display contained "<%\|%>" 178 else 179 syn region cParen transparent start='(' end=')' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cCppParen,@cStringGroup,@Spell 180 " cCppParen: same as cParen but ends at end-of-line; used in cDefine 181 syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell 182 syn match cParenError display ")" 183 syn match cErrInParen display contained "[{}]\|<%\|%>" 184 endif 185 else 186 if s:in_cpp_family && !exists("cpp_no_cpp11") 187 syn region cParen transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell 188 " cCppParen: same as cParen but ends at end-of-line; used in cDefine 189 syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell 190 syn match cParenError display "[\])]" 191 syn match cErrInParen display contained "<%\|%>" 192 syn region cBracket transparent start='\[\|<::\@!' end=']\|:>' contains=ALLBUT,@cParenGroup,cErrInParen,cCppParen,cCppBracket,@cStringGroup,@Spell 193 else 194 syn region cParen transparent start='(' end=')' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell 195 " cCppParen: same as cParen but ends at end-of-line; used in cDefine 196 syn region cCppParen transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell 197 syn match cParenError display "[\])]" 198 syn match cErrInParen display contained "[\]{}]\|<%\|%>" 199 syn region cBracket transparent start='\[\|<::\@!' end=']\|:>' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cErrInParen,cCppParen,cCppBracket,@cStringGroup,@Spell 200 endif 201 " cCppBracket: same as cParen but ends at end-of-line; used in cDefine 202 syn region cCppBracket transparent start='\[\|<::\@!' skip='\\$' excludenl end=']\|:>' end='$' contained contains=ALLBUT,@cParenGroup,cErrInParen,cParen,cBracket,cString,@Spell 203 syn match cErrInBracket display contained "[);{}]\|<%\|%>" 204 endif 205 206 if s:ft ==# 'c' || exists("cpp_no_cpp11") 207 syn region cBadBlock keepend start="{" end="}" contained containedin=cParen,cBracket,cBadBlock transparent fold 208 if !exists("c_no_curly_error") && !exists("c_no_bracket_error") 209 " Do not mistake an unmatched ')' followed by a block for a compound literal. 210 syn region cBadParenBlock keepend transparent start=')\_s*\ze\%({\|<%\)' matchgroup=cErrInBracket end='}\|%>' contained containedin=cBracket,cBadBlock contains=ALLBUT,cBlock,cBadBlock,cInitBlock,@cParenGroup,cErrInParen,cCppParen,cCppBracket,@cStringGroup,@Spell 211 endif 212 endif 213 214 " Compound literals and initializers may appear inside parentheses or brackets. 215 syn region cInitBlock transparent matchgroup=cInitBlock start='\%([)=]\_s*\)\@<=\%({\|<%\)' end='}\|%>' contained containedin=cParen,cBracket,cBadBlock contains=ALLBUT,cBlock,cCurlyError,@cParenGroup,cErrInParen,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell,cInitBlock fold 216 217 "integer number, or floating point number without a dot and with "f". 218 syn case ignore 219 syn match cNumbers display transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctalError,cOctal 220 " Same, but without octal error (for comments) 221 syn match cNumbersCom display contained transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctal 222 223 " cpp.vim handles these 224 if !exists("c_no_c23") && !s:in_cpp_family 225 syn match cNumber display contained "\d\+\%('\d\+\)*\%(u\=l\{0,2}\|ll\=u\|u\=wb\|wbu\=\)\>" 226 "hex number 227 syn match cNumber display contained "0x\x\+\%('\x\+\)*\%(u\=l\{0,2}\|ll\=u\|u\=wb\|wbu\=\)\>" 228 " Flag the first zero of an octal number as something special 229 syn match cOctal display contained "0\o*\%('\o\+\)*\%(u\=l\{0,2}\|ll\=u\|u\=wb\|wbu\=\)\>" contains=cOctalZero 230 "binary number 231 syn match cNumber display contained "0b[01]\+\%('[01]\+\)*\%(u\=l\{0,2}\|ll\=u\|u\=wb\|wbu\=\)\>" 232 else 233 syn match cNumber display contained "\d\+\%(u\=l\{0,2}\|ll\=u\)\>" 234 "hex number 235 syn match cNumber display contained "0x\x\+\%(u\=l\{0,2}\|ll\=u\)\>" 236 " Flag the first zero of an octal number as something special 237 syn match cOctal display contained "0\o\+\%(u\=l\{0,2}\|ll\=u\)\>" contains=cOctalZero 238 syn match cOctalZero display contained "\<0" 239 endif 240 241 if !exists("c_no_c29") && !s:in_cpp_family 242 " XXX: 0-prefixed octal literals e.g. 0123 are obsolescent since C29 243 syn match cOctal display contained "0[Oo]\o\+\%('\o\+\)*\%(u\=l\{0,2}\|ll\=u\|u\=wb\|wbu\=\)\>" 244 endif 245 246 "floating point number, with dot, optional exponent 247 syn match cFloat display contained "\d\+\.\d*\%(e[-+]\=\d\+\)\=[fl]\=" 248 "floating point number, starting with a dot, optional exponent 249 syn match cFloat display contained "\.\d\+\%(e[-+]\=\d\+\)\=[fl]\=\>" 250 "floating point number, without dot, with exponent 251 syn match cFloat display contained "\d\+e[-+]\=\d\+[fl]\=\>" 252 if !exists("c_no_c99") 253 "hexadecimal floating point number, optional leading digits, with dot, with exponent 254 syn match cFloat display contained "0x\x*\.\x\+p[-+]\=\d\+[fl]\=\>" 255 "hexadecimal floating point number, with leading digits, optional dot, with exponent 256 syn match cFloat display contained "0x\x\+\.\=p[-+]\=\d\+[fl]\=\>" 257 endif 258 259 " flag an octal number with wrong digits 260 syn match cOctalError display contained "0\o*[89]\d*" 261 syn case match 262 263 if exists("c_comment_strings") 264 " A comment can contain cString, cCharacter and cNumber. 265 " But a "*/" inside a cString in a cComment DOES end the comment! So we 266 " need to use a special type of cString: cCommentString, which also ends on 267 " "*/", and sees a "*" at the start of the line as comment again. 268 " Unfortunately this doesn't very well work for // type of comments :-( 269 syn match cCommentSkip contained "^\s*\*\%($\|\s\+\)" 270 syn region cCommentString contained start=+L\=\\\@<!"+ skip=+\\\\\|\\"+ end=+"+ end=+\*/+me=s-1 contains=cSpecial,cCommentSkip 271 syn region cComment2String contained start=+L\=\\\@<!"+ skip=+\\\\\|\\"+ end=+"+ end="$" contains=cSpecial 272 syn region cCommentL start="//" skip="\\$" end="$" keepend contains=@cCommentGroup,cComment2String,cCharacter,cNumbersCom,cSpaceError,cWrongComTail,@Spell 273 if exists("c_no_comment_fold") 274 " Use "extend" here to have preprocessor lines not terminate halfway a 275 " comment. 276 syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cCommentString,cCharacter,cNumbersCom,cSpaceError,@Spell extend 277 else 278 syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cCommentString,cCharacter,cNumbersCom,cSpaceError,@Spell fold extend 279 endif 280 else 281 syn region cCommentL start="//" skip="\\$" end="$" keepend contains=@cCommentGroup,cSpaceError,@Spell 282 if exists("c_no_comment_fold") 283 syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cSpaceError,@Spell extend 284 else 285 syn region cComment matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cSpaceError,@Spell fold extend 286 endif 287 endif 288 " keep a // comment separately, it terminates a preproc. conditional 289 syn match cCommentError display "\*/" 290 syn match cCommentStartError display "/\*"me=e-1 contained 291 syn match cWrongComTail display "\*/" 292 293 syn keyword cOperator sizeof 294 if exists("c_gnu") 295 syn keyword cType __label__ __complex__ 296 syn keyword cStatement __asm__ 297 syn keyword cOperator __alignof__ 298 syn keyword cOperator typeof __typeof__ 299 syn keyword cOperator __real__ __imag__ 300 syn keyword cStorageClass __attribute__ __extension__ 301 syn keyword cTypeQualifier __const__ __restrict__ __volatile__ 302 syn keyword cFunctionSpec inline __inline __inline__ __noreturn__ 303 endif 304 syn keyword cType int long short char void 305 syn keyword cType signed unsigned float double 306 if !exists("c_no_ansi") || exists("c_ansi_typedefs") 307 syn keyword cType size_t ssize_t off_t wchar_t ptrdiff_t sig_atomic_t fpos_t 308 syn keyword cType clock_t time_t va_list jmp_buf FILE DIR div_t ldiv_t 309 syn keyword cType mbstate_t wctrans_t wint_t wctype_t 310 endif 311 if !exists("c_no_c99") " ISO C99 312 syn keyword cType _Bool bool _Complex complex _Imaginary imaginary 313 syn keyword cType int8_t int16_t int32_t int64_t 314 syn keyword cType uint8_t uint16_t uint32_t uint64_t 315 if !exists("c_no_bsd") 316 " These are BSD specific. 317 syn keyword cType u_int8_t u_int16_t u_int32_t u_int64_t 318 endif 319 syn keyword cType int_least8_t int_least16_t int_least32_t int_least64_t 320 syn keyword cType uint_least8_t uint_least16_t uint_least32_t uint_least64_t 321 syn keyword cType int_fast8_t int_fast16_t int_fast32_t int_fast64_t 322 syn keyword cType uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t 323 syn keyword cType intptr_t uintptr_t 324 syn keyword cType intmax_t uintmax_t 325 endif 326 if !exists("c_no_c23") && !s:in_cpp_family 327 syn keyword cOperator typeof typeof_unqual 328 syn keyword cType _BitInt _Decimal32 _Decimal64 _Decimal128 329 endif 330 if (s:ft ==# "c" && !exists("c_no_c23")) || (s:in_cpp_family && !exists("cpp_no_cpp11")) 331 syn keyword cType nullptr_t 332 endif 333 334 syn keyword cTypedef typedef 335 syn keyword cStructure struct union enum 336 syn keyword cStorageClass static register auto extern 337 syn keyword cTypeQualifier const volatile 338 if !exists("c_no_c99") && !s:in_cpp_family 339 syn keyword cFunctionSpec inline 340 syn keyword cTypeQualifier restrict 341 endif 342 if (s:ft ==# "c" && !exists("c_no_c23")) || (s:in_cpp_family && !exists("cpp_no_cpp11")) 343 syn keyword cStorageClass constexpr 344 endif 345 if !exists("c_no_c11") 346 syn keyword cStorageClass _Alignas alignas 347 syn keyword cOperator _Alignof alignof 348 syn keyword cTypeQualifier _Atomic 349 syn keyword cOperator _Generic 350 syn keyword cFunctionSpec _Noreturn 351 if !s:in_cpp_family 352 syn keyword cStandardAttribute noreturn 353 endif 354 syn keyword cOperator _Static_assert static_assert 355 syn keyword cStorageClass _Thread_local thread_local 356 syn keyword cType char16_t char32_t 357 syn keyword cType max_align_t 358 " C11 atomics (take down the shield wall!) 359 syn keyword cType atomic_bool atomic_char atomic_schar atomic_uchar 360 syn keyword Ctype atomic_short atomic_ushort atomic_int atomic_uint 361 syn keyword cType atomic_long atomic_ulong atomic_llong atomic_ullong 362 syn keyword cType atomic_char16_t atomic_char32_t atomic_wchar_t 363 syn keyword cType atomic_int_least8_t atomic_uint_least8_t 364 syn keyword cType atomic_int_least16_t atomic_uint_least16_t 365 syn keyword cType atomic_int_least32_t atomic_uint_least32_t 366 syn keyword cType atomic_int_least64_t atomic_uint_least64_t 367 syn keyword cType atomic_int_fast8_t atomic_uint_fast8_t 368 syn keyword cType atomic_int_fast16_t atomic_uint_fast16_t 369 syn keyword cType atomic_int_fast32_t atomic_uint_fast32_t 370 syn keyword cType atomic_int_fast64_t atomic_uint_fast64_t 371 syn keyword cType atomic_intptr_t atomic_uintptr_t 372 syn keyword cType atomic_size_t atomic_ptrdiff_t 373 syn keyword cType atomic_intmax_t atomic_uintmax_t 374 endif 375 376 if !exists("c_no_c23") && !s:in_cpp_family 377 syn keyword cStandardAttribute deprecated fallthrough maybe_unused nodiscard 378 syn keyword cStandardAttribute unsequenced reproducible 379 endif 380 381 if (s:ft ==# "c" && !exists("c_no_c23")) || (s:in_cpp_family && !exists("cpp_no_cpp20")) 382 syn keyword cType char8_t 383 endif 384 385 if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu") 386 if exists("c_gnu") 387 syn keyword cConstant __GNUC__ __FUNCTION__ __PRETTY_FUNCTION__ __func__ 388 endif 389 " TODO: __STDC_HOSTED__ is C99 and C++11 390 syn keyword cConstant __LINE__ __FILE__ __DATE__ __TIME__ __STDC__ __STDC_VERSION__ __STDC_HOSTED__ 391 syn keyword cConstant CHAR_BIT MB_LEN_MAX MB_CUR_MAX 392 syn keyword cConstant UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX 393 syn keyword cConstant CHAR_MIN INT_MIN LONG_MIN SHRT_MIN 394 syn keyword cConstant CHAR_MAX INT_MAX LONG_MAX SHRT_MAX 395 syn keyword cConstant SCHAR_MIN SINT_MIN SLONG_MIN SSHRT_MIN 396 syn keyword cConstant SCHAR_MAX SINT_MAX SLONG_MAX SSHRT_MAX 397 if !exists("c_no_c99") 398 syn keyword cConstant __STDC_ISO_10646__ __STDC_IEC_559_COMPLEX__ 399 syn keyword cConstant __STDC_MB_MIGHT_NEQ_WC__ 400 syn keyword cConstant __func__ __VA_ARGS__ 401 syn keyword cConstant LLONG_MIN LLONG_MAX ULLONG_MAX 402 syn keyword cConstant INT8_MIN INT16_MIN INT32_MIN INT64_MIN 403 syn keyword cConstant INT8_MAX INT16_MAX INT32_MAX INT64_MAX 404 syn keyword cConstant UINT8_MAX UINT16_MAX UINT32_MAX UINT64_MAX 405 syn keyword cConstant INT_LEAST8_MIN INT_LEAST16_MIN INT_LEAST32_MIN INT_LEAST64_MIN 406 syn keyword cConstant INT_LEAST8_MAX INT_LEAST16_MAX INT_LEAST32_MAX INT_LEAST64_MAX 407 syn keyword cConstant UINT_LEAST8_MAX UINT_LEAST16_MAX UINT_LEAST32_MAX UINT_LEAST64_MAX 408 syn keyword cConstant INT_FAST8_MIN INT_FAST16_MIN INT_FAST32_MIN INT_FAST64_MIN 409 syn keyword cConstant INT_FAST8_MAX INT_FAST16_MAX INT_FAST32_MAX INT_FAST64_MAX 410 syn keyword cConstant UINT_FAST8_MAX UINT_FAST16_MAX UINT_FAST32_MAX UINT_FAST64_MAX 411 syn keyword cConstant INTPTR_MIN INTPTR_MAX UINTPTR_MAX 412 syn keyword cConstant INTMAX_MIN INTMAX_MAX UINTMAX_MAX 413 syn keyword cConstant PTRDIFF_MIN PTRDIFF_MAX SIG_ATOMIC_MIN SIG_ATOMIC_MAX 414 syn keyword cConstant SIZE_MAX WCHAR_MIN WCHAR_MAX WINT_MIN WINT_MAX 415 endif 416 if !exists("c_no_c11") 417 syn keyword cConstant __STDC_UTF_16__ __STDC_UTF_32__ __STDC_ANALYZABLE__ 418 syn keyword cConstant __STDC_LIB_EXT1__ __STDC_NO_ATOMICS__ 419 syn keyword cConstant __STDC_NO_COMPLEX__ __STDC_NO_THREADS__ 420 syn keyword cConstant __STDC_NO_VLA__ 421 endif 422 if !exists("c_no_c23") 423 syn keyword cConstant __STDC_UTF_16__ __STDC_UTF_32__ 424 syn keyword cConstant __STDC_EMBED_NOT_FOUND__ __STDC_EMBED_FOUND__ 425 syn keyword cConstant __STDC_EMBED_EMPTY__ __STDC_IEC_60559_BFP__ 426 syn keyword cConstant __STDC_IEC_60559_DFP__ __STDC_IEC_60559_COMPLEX__ 427 syn keyword cConstant __STDC_IEC_60559_TYPES__ 428 syn keyword cConstant BITINT_MAXWIDTH 429 endif 430 if (s:ft ==# "c" && !exists("c_no_c23")) || (s:in_cpp_family && !exists("cpp_no_cpp20")) 431 syn keyword cConstant __VA_OPT__ 432 endif 433 if (s:ft ==# "c" && !exists("c_no_c23")) || (s:in_cpp_family && !exists("cpp_no_cpp11")) 434 syn keyword cConstant nullptr 435 endif 436 syn keyword cConstant FLT_RADIX FLT_ROUNDS FLT_DIG FLT_MANT_DIG FLT_EPSILON DBL_DIG DBL_MANT_DIG DBL_EPSILON 437 syn keyword cConstant LDBL_DIG LDBL_MANT_DIG LDBL_EPSILON FLT_MIN FLT_MAX FLT_MIN_EXP FLT_MAX_EXP FLT_MIN_10_EXP FLT_MAX_10_EXP 438 syn keyword cConstant DBL_MIN DBL_MAX DBL_MIN_EXP DBL_MAX_EXP DBL_MIN_10_EXP DBL_MAX_10_EXP LDBL_MIN LDBL_MAX LDBL_MIN_EXP LDBL_MAX_EXP 439 syn keyword cConstant LDBL_MIN_10_EXP LDBL_MAX_10_EXP HUGE_VAL CLOCKS_PER_SEC NULL LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY 440 syn keyword cConstant LC_NUMERIC LC_TIME SIG_DFL SIG_ERR SIG_IGN SIGABRT SIGFPE SIGILL SIGHUP SIGINT SIGSEGV SIGTERM 441 " Add POSIX signals as well... 442 syn keyword cConstant SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV 443 syn keyword cConstant SIGSTOP SIGTERM SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2 444 syn keyword cConstant _IOFBF _IOLBF _IONBF BUFSIZ EOF WEOF FOPEN_MAX FILENAME_MAX L_tmpnam 445 syn keyword cConstant SEEK_CUR SEEK_END SEEK_SET TMP_MAX EXIT_FAILURE EXIT_SUCCESS RAND_MAX 446 syn keyword cConstant stdin stdout stderr 447 " POSIX 2001, in unistd.h 448 syn keyword cConstant STDIN_FILENO STDOUT_FILENO STDERR_FILENO 449 " used in assert.h 450 syn keyword cConstant NDEBUG 451 " POSIX 2001 452 syn keyword cConstant SIGBUS SIGPOLL SIGPROF SIGSYS SIGURG SIGVTALRM SIGXCPU SIGXFSZ 453 " POSIX Issue 8 (post 2017) 454 syn keyword cConstant SIGWINCH 455 " non-POSIX signals 456 syn keyword cConstant SIGINFO SIGIO 457 " Add POSIX errors as well. List comes from: 458 " http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html 459 syn keyword cConstant E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT EAGAIN EALREADY EBADF 460 syn keyword cConstant EBADMSG EBUSY ECANCELED ECHILD ECONNABORTED ECONNREFUSED ECONNRESET EDEADLK 461 syn keyword cConstant EDESTADDRREQ EDOM EDQUOT EEXIST EFAULT EFBIG EHOSTUNREACH EIDRM EILSEQ 462 syn keyword cConstant EINPROGRESS EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK EMSGSIZE 463 syn keyword cConstant EMULTIHOP ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH ENFILE ENOBUFS ENODATA 464 syn keyword cConstant ENODEV ENOENT ENOEXEC ENOLCK ENOLINK ENOMEM ENOMSG ENOPROTOOPT ENOSPC ENOSR 465 syn keyword cConstant ENOSTR ENOSYS ENOTBLK ENOTCONN ENOTDIR ENOTEMPTY ENOTRECOVERABLE ENOTSOCK ENOTSUP 466 syn keyword cConstant ENOTTY ENXIO EOPNOTSUPP EOVERFLOW EOWNERDEAD EPERM EPIPE EPROTO 467 syn keyword cConstant EPROTONOSUPPORT EPROTOTYPE ERANGE EROFS ESPIPE ESRCH ESTALE ETIME ETIMEDOUT 468 syn keyword cConstant ETXTBSY EWOULDBLOCK EXDEV 469 " math.h 470 syn keyword cConstant M_E M_LOG2E M_LOG10E M_LN2 M_LN10 M_PI M_PI_2 M_PI_4 471 syn keyword cConstant M_1_PI M_2_PI M_2_SQRTPI M_SQRT2 M_SQRT1_2 472 endif 473 if !exists("c_no_c99") " ISO C99 474 syn keyword cConstant true false 475 syn keyword cConstant INFINITY NAN 476 " math.h 477 syn keyword cConstant HUGE_VAL HUGE_VALF HUGE_VALL 478 syn keyword cConstant FP_FAST_FMAF FP_FAST_FMA FP_FAST_FMAL 479 syn keyword cConstant FP_ILOGB0 FP_ILOGBNAN 480 syn keyword cConstant math_errhandling MATH_ERRNO MATH_ERREXCEPT 481 syn keyword cConstant FP_NORMAL FP_SUBNORMAL FP_ZERO FP_INFINITE FP_NAN 482 endif 483 484 " Accept %: for # (C99) 485 syn cluster cPreProcGroup contains=cPreCondit,cIncluded,cInclude,cDefine,cErrInParen,cErrInBracket,cUserLabel,cSpecial,cOctalZero,cCppOutWrapper,cCppInWrapper,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cString,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cParen,cBracket,cMulti,cBadBlock 486 if !exists("c_no_c23") 487 syn region cPreCondit start="^\s*\zs\%(%:\|#\)\s*\%(el\)\=\%(if\|ifdef\|ifndef\)\>" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError 488 else 489 syn region cPreCondit start="^\s*\zs\%(%:\|#\)\s*\%(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError 490 endif 491 syn match cPreConditMatch display "^\s*\zs\%(%:\|#\)\s*\%(else\|endif\)\>" 492 if !exists("c_no_if0") 493 syn cluster cCppOutInGroup contains=cCppInIf,cCppInElse,cCppInElse2,cCppOutIf,cCppOutIf2,cCppOutElse,cCppInSkip,cCppOutSkip 494 syn region cCppOutWrapper start="^\s*\zs\%(%:\|#\)\s*if\s\+0\+\s*\%($\|//\|/\*\|&\)" end=".\@=\|$" contains=cCppOutIf,cCppOutElse,@NoSpell fold 495 syn region cCppOutIf contained start="0\+" matchgroup=cCppOutWrapper end="^\s*\%(%:\|#\)\s*endif\>" contains=cCppOutIf2,cCppOutElse 496 if !exists("c_no_if0_fold") 497 if !exists("c_no_c23") 498 syn region cCppOutIf2 contained matchgroup=cCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|el\%(if\|ifdef\|ifndef\)\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell fold 499 else 500 syn region cCppOutIf2 contained matchgroup=cCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell fold 501 endif 502 else 503 if !exists("c_no_c23") 504 syn region cCppOutIf2 contained matchgroup=cCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|el\%(if\|ifdef\|ifndef\)\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell 505 else 506 syn region cCppOutIf2 contained matchgroup=cCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell 507 endif 508 endif 509 if !exists("c_no_c23") 510 syn region cCppOutElse contained matchgroup=cCppOutWrapper start="^\s*\%(%:\|#\)\s*\%(else\|el\%(if\|ifdef\|ifndef\)\)" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=TOP,cPreCondit 511 else 512 syn region cCppOutElse contained matchgroup=cCppOutWrapper start="^\s*\%(%:\|#\)\s*\%(else\|elif\)" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=TOP,cPreCondit 513 endif 514 syn region cCppInWrapper start="^\s*\zs\%(%:\|#\)\s*if\s\+0*[1-9]\d*\s*\%($\|//\|/\*\||\)" end=".\@=\|$" contains=cCppInIf,cCppInElse fold 515 syn region cCppInIf contained matchgroup=cCppInWrapper start="\d\+" end="^\s*\%(%:\|#\)\s*endif\>" contains=TOP,cPreCondit 516 if !exists("c_no_if0_fold") 517 if !exists("c_no_c23") 518 syn region cCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|el\%(if\|ifdef\|ifndef\)\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2 fold 519 else 520 syn region cCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2 fold 521 endif 522 else 523 if !exists("c_no_c23") 524 syn region cCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|el\%(if\|ifdef\|ifndef\)\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2 525 else 526 syn region cCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2 527 endif 528 endif 529 if !exists("c_no_c23") 530 syn region cCppInElse2 contained matchgroup=cCppInWrapper start="^\s*\%(%:\|#\)\s*\%(else\|el\%(if\|ifdef\|ifndef\)\)\%([^/]\|/[^/*]\)*" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell 531 else 532 syn region cCppInElse2 contained matchgroup=cCppInWrapper start="^\s*\%(%:\|#\)\s*\%(else\|elif\)\%([^/]\|/[^/*]\)*" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell 533 endif 534 syn region cCppOutSkip contained start="^\s*\%(%:\|#\)\s*\%(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\%(%:\|#\)\s*endif\>" contains=cSpaceError,cCppOutSkip 535 syn region cCppInSkip contained matchgroup=cCppInWrapper start="^\s*\%(%:\|#\)\s*\%(if\s\+\%(\d\+\s*\%($\|//\|/\*\||\|&\)\)\@!\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\%(%:\|#\)\s*endif\>" containedin=cCppOutElse,cCppInIf,cCppInSkip contains=TOP,cPreProc 536 endif 537 syn region cIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+ 538 syn match cIncluded display contained "<[^>]*>" 539 syn match cInclude display "^\s*\zs\%(%:\|#\)\s*include\>\s*["<]" contains=cIncluded 540 if !exists("c_no_c23") && !s:in_cpp_family 541 syn region cInclude start="^\s*\zs\%(%:\|#\)\s*embed\>" skip="\\$" end="$" keepend contains=cEmbed,cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError 542 syn match cEmbed contained "\%(%:\|#\)\s*embed\>" nextgroup=cIncluded skipwhite transparent 543 syn cluster cPreProcGroup add=cEmbed 544 endif 545 "syn match cLineSkip "\\$" 546 syn region cDefine start="^\s*\zs\%(%:\|#\)\s*\%(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell 547 syn region cPreProc start="^\s*\zs\%(%:\|#\)\s*\%(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell 548 549 " Optional embedded Autodoc parsing 550 if exists("c_autodoc") 551 syn match cAutodocReal display contained "\%(//\|[/ \t\v]\*\|^\*\)\@2<=!.*" contains=@cAutodoc containedin=cComment,cCommentL 552 syn cluster cCommentGroup add=cAutodocReal 553 syn cluster cPreProcGroup add=cAutodocReal 554 endif 555 556 " be able to fold #pragma regions 557 syn region cPragma start="^\s*#pragma\s\+region\>" end="^\s*#pragma\s\+endregion\>" transparent keepend extend fold 558 559 " Highlight User Labels 560 syn cluster cMultiGroup contains=cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOutWrapper,cCppInWrapper,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cCppParen,cCppBracket,cCppString 561 if s:ft ==# 'c' || exists("cpp_no_cpp11") 562 syn region cMulti transparent start='?' skip='::' end=':' contains=ALLBUT,@cMultiGroup,@Spell,@cStringGroup 563 endif 564 " Avoid matching foo::bar() in C++ by requiring that the next char is not ':' 565 syn cluster cLabelGroup contains=cUserLabel 566 syn match cUserCont display "^\s*\zs\I\i*\s*:$" contains=@cLabelGroup 567 syn match cUserCont display ";\s*\zs\I\i*\s*:$" contains=@cLabelGroup 568 if s:in_cpp_family 569 syn match cUserCont display "^\s*\zs\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup 570 syn match cUserCont display ";\s*\zs\%(class\|struct\|enum\)\@!\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup 571 else 572 syn match cUserCont display "^\s*\zs\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup 573 syn match cUserCont display ";\s*\zs\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup 574 endif 575 576 syn match cUserLabel display "\I\i*" contained 577 578 " Avoid recognizing most bitfields as labels 579 syn match cBitField display "^\s*\zs\I\i*\s*:\s*[1-9]"me=e-1 contains=cType 580 syn match cBitField display ";\s*\zs\I\i*\s*:\s*[1-9]"me=e-1 contains=cType 581 582 if exists("c_functions") 583 syn match cFunction "\<\h\w*\ze\_s*(" 584 endif 585 586 if exists("c_function_pointers") 587 syn match cFunctionPointer "\%((\s*\*\s*\)\@<=\h\w*\ze\s*)\_s*(.*)" 588 endif 589 590 if exists("c_minlines") 591 let b:c_minlines = c_minlines 592 else 593 if !exists("c_no_if0") 594 let b:c_minlines = 50 " #if 0 constructs can be long 595 else 596 let b:c_minlines = 15 " mostly for () constructs 597 endif 598 endif 599 if exists("c_curly_error") 600 syn sync fromstart 601 else 602 exec "syn sync ccomment cComment minlines=" . b:c_minlines 603 endif 604 605 " Define the default highlighting. 606 " Only used when an item doesn't have highlighting yet 607 hi def link cFormat cSpecial 608 hi def link cCppString cString 609 hi def link cCommentL cComment 610 hi def link cCommentStart cComment 611 hi def link cLabel Label 612 hi def link cUserLabel Label 613 hi def link cConditional Conditional 614 hi def link cRepeat Repeat 615 hi def link cCharacter Character 616 hi def link cSpecialCharacter cSpecial 617 hi def link cNumber Number 618 hi def link cOctal Number 619 hi def link cOctalZero PreProc " link this to Error if you want 620 hi def link cFloat Float 621 hi def link cOctalError cError 622 hi def link cParenError cError 623 hi def link cErrInParen cError 624 hi def link cErrInBracket cError 625 hi def link cCommentError cError 626 hi def link cCommentStartError cError 627 hi def link cSpaceError cError 628 hi def link cWrongComTail cError 629 hi def link cSpecialError cError 630 hi def link cCurlyError cError 631 hi def link cOperator Operator 632 hi def link cStructure Structure 633 hi def link cTypedef Structure 634 hi def link cStorageClass StorageClass 635 hi def link cTypeQualifier cStorageClass 636 hi def link cFunctionSpec cStorageClass 637 hi def link cStandardAttribute cStorageClass 638 hi def link cInclude Include 639 hi def link cPreProc PreProc 640 hi def link cDefine Macro 641 hi def link cIncluded cString 642 hi def link cError Error 643 hi def link cStatement Statement 644 hi def link cCppInWrapper cCppOutWrapper 645 hi def link cCppOutWrapper cPreCondit 646 hi def link cPreConditMatch cPreCondit 647 hi def link cPreCondit PreCondit 648 hi def link cType Type 649 hi def link cConstant Constant 650 hi def link cCommentString cString 651 hi def link cComment2String cString 652 hi def link cCommentSkip cComment 653 hi def link cString String 654 hi def link cComment Comment 655 hi def link cSpecial SpecialChar 656 hi def link cTodo Todo 657 hi def link cBadContinuation Error 658 hi def link cCppOutSkip cCppOutIf2 659 hi def link cCppInElse2 cCppOutIf2 660 hi def link cCppOutIf2 cCppOut 661 hi def link cCppOut Comment 662 hi def link cFunction Function 663 hi def link cFunctionPointer Function 664 665 let b:current_syntax = "c" 666 667 unlet s:ft 668 669 let &cpo = s:cpo_save 670 unlet s:cpo_save 671 " vim: ts=8