11" Vim syntax file
2- " Language: C
3- " Maintainer: The Vim Project <https://github.com/vim/vim>
4- " Last Change: 2023 Aug 10
2+ " Language: C
3+ " Maintainer: The Vim Project <https://github.com/vim/vim>
4+ " Last Change: 2025 Jan 15
55" Former Maintainer: Bram Moolenaar <Bram@vim.org>
66
77" Quit when a (custom) syntax file was already loaded
@@ -111,6 +111,20 @@ if (s:ft ==# "c" && !exists("c_no_c11")) || (s:in_cpp_family && !exists("cpp_no_
111111 syn match cSpecialCharacter display " [Uu]'\\ x\x\+ '"
112112endif
113113
114+ if (s: ft == # " c" && ! exists (" c_no_c23" )) || (s: in_cpp_family && ! exists (" cpp_no_cpp17" ))
115+ syn match cCharacter " u8'[^\\ ]'"
116+ syn match cCharacter " u8'[^']*'" contains =cSpecial
117+ if exists (" c_gnu" )
118+ syn match cSpecialError " u8'\\ [^'\" ?\\ abefnrtv]'"
119+ syn match cSpecialCharacter " u8'\\ ['\" ?\\ abefnrtv]'"
120+ else
121+ syn match cSpecialError " u8'\\ [^'\" ?\\ abfnrtv]'"
122+ syn match cSpecialCharacter " u8'\\ ['\" ?\\ abfnrtv]'"
123+ endif
124+ syn match cSpecialCharacter display " u8'\\\o\{ 1,3}'"
125+ syn match cSpecialCharacter display " u8'\\ x\x\+ '"
126+ endif
127+
114128" when wanted, highlight trailing white space
115129if exists (" c_space_errors" )
116130 if ! exists (" c_no_trail_space_error" )
@@ -191,12 +205,25 @@ syn case ignore
191205syn match cNumbers display transparent " \<\d\|\.\d " contains =cNumber,cFloat,cOctalError,cOctal
192206" Same, but without octal error (for comments)
193207syn match cNumbersCom display contained transparent " \<\d\|\.\d " contains =cNumber,cFloat,cOctal
194- syn match cNumber display contained " \d\+\% (u\= l\{ 0,2}\| ll\= u\)\> "
195- " hex number
196- syn match cNumber display contained " 0x\x\+\% (u\= l\{ 0,2}\| ll\= u\)\> "
197- " Flag the first zero of an octal number as something special
198- syn match cOctal display contained " 0\o\+\% (u\= l\{ 0,2}\| ll\= u\)\> " contains =cOctalZero
199- syn match cOctalZero display contained " \< 0"
208+
209+ " cpp.vim handles these
210+ if ! exists (" c_no_c23" ) && ! s: in_cpp_family
211+ syn match cNumber display contained " \d\% ('\=\d\+\) *\% (u\= l\{ 0,2}\| ll\= u\| u\= wb\| wbu\=\)\> "
212+ " hex number
213+ syn match cNumber display contained " 0x\x\% ('\=\x\+\) *\% (u\= l\{ 0,2}\| ll\= u\| u\= wb\| wbu\=\)\> "
214+ " Flag the first zero of an octal number as something special
215+ syn match cOctal display contained " 0\o\% ('\=\o\+\) *\% (u\= l\{ 0,2}\| ll\= u\| u\= wb\| wbu\=\)\> " contains =cOctalZero
216+ " binary number
217+ syn match cNumber display contained " 0b[01]\% ('\= [01]\+\) *\% (u\= l\{ 0,2}\| ll\= u\| u\= wb\| wbu\=\)\> "
218+ else
219+ syn match cNumber display contained " \d\+\% (u\= l\{ 0,2}\| ll\= u\)\> "
220+ " hex number
221+ syn match cNumber display contained " 0x\x\+\% (u\= l\{ 0,2}\| ll\= u\)\> "
222+ " Flag the first zero of an octal number as something special
223+ syn match cOctal display contained " 0\o\+\% (u\= l\{ 0,2}\| ll\= u\)\> " contains =cOctalZero
224+ syn match cOctalZero display contained " \< 0"
225+ endif
226+
200227" floating point number, with dot, optional exponent
201228syn match cFloat display contained " \d\+\.\d *\% (e[-+]\=\d\+\)\= [fl]\= "
202229" floating point number, starting with a dot, optional exponent
@@ -277,6 +304,13 @@ if !exists("c_no_c99") " ISO C99
277304 syn keyword cType intptr_t uintptr_t
278305 syn keyword cType intmax_t uintmax_t
279306endif
307+ if ! exists (" c_no_c23" ) && ! s: in_cpp_family
308+ syn keyword cOperator typeof typeof_unqual
309+ syn keyword cType _BitInt _Decimal32 _Decimal64 _Decimal128
310+ endif
311+ if (s: ft == # " c" && ! exists (" c_no_c23" )) || (s: in_cpp_family && ! exists (" cpp_no_cpp11" ))
312+ syn keyword cType nullptr_t
313+ endif
280314
281315syn keyword cTypedef typedef
282316syn keyword cStructure struct union enum
@@ -312,10 +346,15 @@ if !exists("c_no_c11")
312346 syn keyword cType atomic_intmax_t atomic_uintmax_t
313347endif
314348
349+ if (s: ft == # " c" && ! exists (" c_no_c23" )) || (s: in_cpp_family && ! exists (" cpp_no_cpp20" ))
350+ syn keyword cType char8_t
351+ endif
352+
315353if ! exists (" c_no_ansi" ) || exists (" c_ansi_constants" ) || exists (" c_gnu" )
316354 if exists (" c_gnu" )
317355 syn keyword cConstant __GNUC__ __FUNCTION__ __PRETTY_FUNCTION__ __func__
318356 endif
357+ " TODO: __STDC_HOSTED__ is C99 and C++11
319358 syn keyword cConstant __LINE__ __FILE__ __DATE__ __TIME__ __STDC__ __STDC_VERSION__ __STDC_HOSTED__
320359 syn keyword cConstant CHAR_BIT MB_LEN_MAX MB_CUR_MAX
321360 syn keyword cConstant UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX
@@ -324,6 +363,8 @@ if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu")
324363 syn keyword cConstant SCHAR_MIN SINT_MIN SLONG_MIN SSHRT_MIN
325364 syn keyword cConstant SCHAR_MAX SINT_MAX SLONG_MAX SSHRT_MAX
326365 if ! exists (" c_no_c99" )
366+ syn keyword cConstant __STDC_ISO_10646__ __STDC_IEC_559_COMPLEX__
367+ syn keyword cConstant __STDC_MB_MIGHT_NEQ_WC__
327368 syn keyword cConstant __func__ __VA_ARGS__
328369 syn keyword cConstant LLONG_MIN LLONG_MAX ULLONG_MAX
329370 syn keyword cConstant INT8_MIN INT16_MIN INT32_MIN INT64_MIN
@@ -340,6 +381,26 @@ if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu")
340381 syn keyword cConstant PTRDIFF_MIN PTRDIFF_MAX SIG_ATOMIC_MIN SIG_ATOMIC_MAX
341382 syn keyword cConstant SIZE_MAX WCHAR_MIN WCHAR_MAX WINT_MIN WINT_MAX
342383 endif
384+ if ! exists (" c_no_c11" )
385+ syn keyword cConstant __STDC_UTF_16__ __STDC_UTF_32__ __STDC_ANALYZABLE__
386+ syn keyword cConstant __STDC_LIB_EXT1__ __STDC_NO_ATOMICS__
387+ syn keyword cConstant __STDC_NO_COMPLEX__ __STDC_NO_THREADS__
388+ syn keyword cConstant __STDC_NO_VLA__
389+ endif
390+ if ! exists (" c_no_c23" )
391+ syn keyword cConstant __STDC_UTF_16__ __STDC_UTF_32__
392+ syn keyword cConstant __STDC_EMBED_NOT_FOUND__ __STDC_EMBED_FOUND__
393+ syn keyword cConstant __STDC_EMBED_EMPTY__ __STDC_IEC_60559_BFP__
394+ syn keyword cConstant __STDC_IEC_60559_DFP__ __STDC_IEC_60559_COMPLEX__
395+ syn keyword cConstant __STDC_IEC_60559_TYPES__
396+ syn keyword cConstant BITINT_MAXWIDTH
397+ endif
398+ if (s: ft == # " c" && ! exists (" c_no_c23" )) || (s: in_cpp_family && ! exists (" cpp_no_cpp20" ))
399+ syn keyword cConstant __VA_OPT__
400+ endif
401+ if (s: ft == # " c" && ! exists (" c_no_c23" )) || (s: in_cpp_family && ! exists (" cpp_no_cpp11" ))
402+ syn keyword cConstant nullptr
403+ endif
343404 syn keyword cConstant FLT_RADIX FLT_ROUNDS FLT_DIG FLT_MANT_DIG FLT_EPSILON DBL_DIG DBL_MANT_DIG DBL_EPSILON
344405 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
345406 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
@@ -377,37 +438,77 @@ if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu")
377438endif
378439if ! exists (" c_no_c99" ) " ISO C99
379440 syn keyword cConstant true false
441+ syn keyword cConstant INFINITY NAN
442+ " math.h
443+ syn keyword cConstant HUGE_VAL HUGE_VALF HUGE_VALL
444+ syn keyword cConstant FP_FAST_FMAF FP_FAST_FMA FP_FAST_FMAL
445+ syn keyword cConstant FP_ILOGB0 FP_ILOGBNAN
446+ syn keyword cConstant math_errhandling MATH_ERRNO MATH_ERREXCEPT
447+ syn keyword cConstant FP_NORMAL FP_SUBNORMAL FP_ZERO FP_INFINITE FP_NAN
380448endif
381449
382450" Accept %: for # (C99)
383- syn region cPreCondit start =" ^\s *\z s\% (%:\| #\)\s *\% (if\| ifdef\| ifndef\| elif\)\> " skip =" \\ $" end =" $" keepend contains =cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
451+ 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
452+ if ! exists (" c_no_c23" )
453+ syn region cPreCondit start =" ^\s *\z s\% (%:\| #\)\s *\% (el\)\=\% (if\| ifdef\| ifndef\)\> " skip =" \\ $" end =" $" keepend contains =cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
454+ else
455+ syn region cPreCondit start =" ^\s *\z s\% (%:\| #\)\s *\% (if\| ifdef\| ifndef\| elif\)\> " skip =" \\ $" end =" $" keepend contains =cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
456+ endif
384457syn match cPreConditMatch display " ^\s *\z s\% (%:\| #\)\s *\% (else\| endif\)\> "
385458if ! exists (" c_no_if0" )
386459 syn cluster cCppOutInGroup contains =cCppInIf,cCppInElse,cCppInElse2,cCppOutIf,cCppOutIf2,cCppOutElse,cCppInSkip,cCppOutSkip
387460 syn region cCppOutWrapper start =" ^\s *\z s\% (%:\| #\)\s *if\s\+ 0\+\s *\% ($\| //\| /\*\| &\) " end =" .\@ =\| $" contains =cCppOutIf,cCppOutElse,@NoSpell fold
388461 syn region cCppOutIf contained start =" 0\+ " matchgroup =cCppOutWrapper end =" ^\s *\% (%:\| #\)\s *endif\> " contains =cCppOutIf2,cCppOutElse
389462 if ! exists (" c_no_if0_fold" )
390- 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
463+ if ! exists (" c_no_c23" )
464+ 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
465+ else
466+ 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
467+ endif
391468 else
392- syn region cCppOutIf2 contained matchgroup =cCppOutWrapper start =" 0\+ " end =" ^\s *\% (%:\| #\)\s *\% (else\>\| elif\s\+\% (0\+\s *\% ($\| //\| /\*\| &\)\)\@ !\| endif\>\) " me =s - 1 contains =cSpaceError,cCppOutSkip,@Spell
469+ if ! exists (" c_no_c23" )
470+ 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
471+ else
472+ syn region cCppOutIf2 contained matchgroup =cCppOutWrapper start =" 0\+ " end =" ^\s *\% (%:\| #\)\s *\% (else\>\| elif\s\+\% (0\+\s *\% ($\| //\| /\*\| &\)\)\@ !\| endif\>\) " me =s - 1 contains =cSpaceError,cCppOutSkip,@Spell
473+ endif
474+ endif
475+ if ! exists (" c_no_c23" )
476+ syn region cCppOutElse contained matchgroup =cCppOutWrapper start =" ^\s *\% (%:\| #\)\s *\% (else\| el\% (if\| ifdef\| ifndef\)\) " end =" ^\s *\% (%:\| #\)\s *endif\> " me =s - 1 contains =TOP,cPreCondit
477+ else
478+ syn region cCppOutElse contained matchgroup =cCppOutWrapper start =" ^\s *\% (%:\| #\)\s *\% (else\| elif\) " end =" ^\s *\% (%:\| #\)\s *endif\> " me =s - 1 contains =TOP,cPreCondit
393479 endif
394- syn region cCppOutElse contained matchgroup =cCppOutWrapper start =" ^\s *\% (%:\| #\)\s *\% (else\| elif\) " end =" ^\s *\% (%:\| #\)\s *endif\> " me =s - 1 contains =TOP,cPreCondit
395480 syn region cCppInWrapper start =" ^\s *\z s\% (%:\| #\)\s *if\s\+ 0*[1-9]\d *\s *\% ($\| //\| /\*\| |\) " end =" .\@ =\| $" contains =cCppInIf,cCppInElse fold
396481 syn region cCppInIf contained matchgroup =cCppInWrapper start =" \d\+ " end =" ^\s *\% (%:\| #\)\s *endif\> " contains =TOP,cPreCondit
397482 if ! exists (" c_no_if0_fold" )
398- syn region cCppInElse contained start =" ^\s *\% (%:\| #\)\s *\% (else\>\| elif\s\+\% (0*[1-9]\d *\s *\% ($\| //\| /\*\| |\)\)\@ !\) " end =" .\@ =\| $" containedin =cCppInIf contains =cCppInElse2 fold
483+ if ! exists (" c_no_c23" )
484+ syn region cCppInElse contained start =" ^\s *\% (%:\| #\)\s *\% (else\>\| el\% (if\| ifdef\| ifndef\)\s\+\% (0*[1-9]\d *\s *\% ($\| //\| /\*\| |\)\)\@ !\) " end =" .\@ =\| $" containedin =cCppInIf contains =cCppInElse2 fold
485+ else
486+ syn region cCppInElse contained start =" ^\s *\% (%:\| #\)\s *\% (else\>\| elif\s\+\% (0*[1-9]\d *\s *\% ($\| //\| /\*\| |\)\)\@ !\) " end =" .\@ =\| $" containedin =cCppInIf contains =cCppInElse2 fold
487+ endif
488+ else
489+ if ! exists (" c_no_c23" )
490+ syn region cCppInElse contained start =" ^\s *\% (%:\| #\)\s *\% (else\>\| el\% (if\| ifdef\| ifndef\)\s\+\% (0*[1-9]\d *\s *\% ($\| //\| /\*\| |\)\)\@ !\) " end =" .\@ =\| $" containedin =cCppInIf contains =cCppInElse2
491+ else
492+ syn region cCppInElse contained start =" ^\s *\% (%:\| #\)\s *\% (else\>\| elif\s\+\% (0*[1-9]\d *\s *\% ($\| //\| /\*\| |\)\)\@ !\) " end =" .\@ =\| $" containedin =cCppInIf contains =cCppInElse2
493+ endif
494+ endif
495+ if ! exists (" c_no_c23" )
496+ 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
399497 else
400- syn region cCppInElse contained start =" ^\s *\% (%:\| #\)\s *\% (else\>\ | elif\s\+\% (0*[1-9] \d * \s * \% ($ \| // \| / \*\| | \)\)\@ ! \) " end =" . \@ = \| $ " containedin = cCppInIf contains =cCppInElse2
498+ syn region cCppInElse2 contained matchgroup = cCppInWrapper start =" ^\s *\% (%:\| #\)\s *\% (else\| elif\)\% ([^/] \| /[^/*] \) * " end =" ^ \s * \% (%: \| # \)\s *endif \> " me = s - 1 contains =cSpaceError,cCppOutSkip,@Spell
401499 endif
402- syn region cCppInElse2 contained matchgroup =cCppInWrapper start =" ^\s *\% (%:\| #\)\s *\% (else\| elif\)\% ([^/]\| /[^/*]\) *" end =" ^\s *\% (%:\| #\)\s *endif\> " me =s - 1 contains =cSpaceError,cCppOutSkip,@Spell
403500 syn region cCppOutSkip contained start =" ^\s *\% (%:\| #\)\s *\% (if\>\| ifdef\>\| ifndef\>\) " skip =" \\ $" end =" ^\s *\% (%:\| #\)\s *endif\> " contains =cSpaceError,cCppOutSkip
404501 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
405502endif
406503syn region cIncluded display contained start =+ "+ skip =+ \\\\\|\\ "+ end =+ "+
407504syn match cIncluded display contained " <[^>]*>"
408505syn match cInclude display " ^\s *\z s\% (%:\| #\)\s *include\>\s *["<]" contains =cIncluded
506+ if ! exists (" c_no_c23" ) && ! s: in_cpp_family
507+ syn region cInclude start =" ^\s *\z s\% (%:\| #\)\s *embed\> " skip =" \\ $" end =" $" keepend contains =cEmbed,cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
508+ syn match cEmbed contained " \% (%:\| #\)\s *embed\> " nextgroup =cIncluded skipwhite transparent
509+ syn cluster cPreProcGroup add =cEmbed
510+ endif
409511" syn match cLineSkip "\\$"
410- 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
411512syn region cDefine start =" ^\s *\z s\% (%:\| #\)\s *\% (define\| undef\)\> " skip =" \\ $" end =" $" keepend contains =ALLBUT,@cPreProcGroup,@Spell
412513syn region cPreProc start =" ^\s *\z s\% (%:\| #\)\s *\% (pragma\>\| line\>\| warning\>\| warn\>\| error\>\) " skip =" \\ $" end =" $" keepend contains =ALLBUT,@cPreProcGroup,@Spell
413514
0 commit comments