cpp.vim (6326B)
1 " Vim syntax file 2 " Language: C++ 3 " Maintainer: This runtime file is looking for a new maintainer. 4 " Previous Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp) 5 " Ken Shan <ccshan@post.harvard.edu> 6 " Last Change: 2024 May 04 7 " 2024 May 04 by Vim Project fix digit separator in octals and floats 8 " 2026 Jan 06 by Vim Project orphaning announcement 9 " 2026 Jan 08 by Vim Project highlight capital letter prefixes for numbers 10 11 " quit when a syntax file was already loaded 12 if exists("b:current_syntax") 13 finish 14 endif 15 16 " inform C syntax that the file was included from cpp.vim 17 let b:filetype_in_cpp_family = 1 18 19 " Read the C syntax to start with 20 runtime! syntax/c.vim 21 unlet b:current_syntax 22 unlet b:filetype_in_cpp_family 23 24 " C++ extensions 25 syn keyword cppStatement new delete this friend using 26 syn keyword cppAccess public protected private 27 syn keyword cppModifier inline virtual explicit export 28 syn keyword cppType bool wchar_t 29 syn keyword cppExceptions throw try catch 30 syn keyword cppOperator operator typeid 31 syn keyword cppOperator and bitor or xor compl bitand and_eq or_eq xor_eq not not_eq 32 syn match cppCast "\<\(const\|static\|dynamic\|reinterpret\)_cast\s*<"me=e-1 33 syn match cppCast "\<\(const\|static\|dynamic\|reinterpret\)_cast\s*$" 34 syn keyword cppStorageClass mutable 35 syn keyword cppStructure class typename template namespace 36 syn keyword cppBoolean true false 37 syn keyword cppConstant __cplusplus 38 39 " C++ 11 extensions 40 if !exists("cpp_no_cpp11") 41 syn keyword cppModifier override final 42 syn keyword cppType nullptr_t auto 43 syn keyword cppExceptions noexcept 44 syn keyword cppStorageClass constexpr decltype thread_local 45 syn keyword cppConstant nullptr 46 syn keyword cppConstant ATOMIC_FLAG_INIT ATOMIC_VAR_INIT 47 syn keyword cppConstant ATOMIC_BOOL_LOCK_FREE ATOMIC_CHAR_LOCK_FREE 48 syn keyword cppConstant ATOMIC_CHAR16_T_LOCK_FREE ATOMIC_CHAR32_T_LOCK_FREE 49 syn keyword cppConstant ATOMIC_WCHAR_T_LOCK_FREE ATOMIC_SHORT_LOCK_FREE 50 syn keyword cppConstant ATOMIC_INT_LOCK_FREE ATOMIC_LONG_LOCK_FREE 51 syn keyword cppConstant ATOMIC_LLONG_LOCK_FREE ATOMIC_POINTER_LOCK_FREE 52 syn region cppRawString matchgroup=cppRawStringDelimiter start=+\%(u8\|[uLU]\)\=R"\z([[:alnum:]_{}[\]#<>%:;.?*\+\-/\^&|~!=,"']\{,16}\)(+ end=+)\z1"\(sv\|s\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=+ contains=@Spell 53 syn match cppCast "\<\(const\|static\|dynamic\)_pointer_cast\s*<"me=e-1 54 syn match cppCast "\<\(const\|static\|dynamic\)_pointer_cast\s*$" 55 endif 56 57 " C++ 14 extensions 58 if !exists("cpp_no_cpp14") 59 syn match cppNumbers display transparent "\<\d\|\.\d" contains=cppNumber,cppFloat 60 syn match cppNumber display contained "\<0\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" 61 syn match cppNumber display contained "\<[1-9]\('\=\d\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" 62 syn match cppNumber display contained "\<0\('\=\o\+\)\+\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" 63 syn match cppNumber display contained "\<0[Bb][01]\('\=[01]\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" 64 syn match cppNumber display contained "\<0[Xx]\x\('\=\x\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" 65 syn match cppFloat display contained "\<\d\('\=\d\+\)*\.\(\d\('\=\d\+\)*\)\=\([Ee][-+]\=\d\+\)\=\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" 66 syn match cppFloat display contained "\.\d\('\=\d\+\)*\([Ee][-+]\=\d\+\)\=\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" 67 syn match cppFloat display contained "\<\d\+[Ee][-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" 68 syn region cppString start=+\(L\|u\|u8\|U\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_\i*\)\=+ end='$' contains=cSpecial,cFormat,@Spell 69 endif 70 71 " C++ 17 extensions 72 if !exists("cpp_no_cpp17") 73 syn match cppCast "\<reinterpret_pointer_cast\s*<"me=e-1 74 syn match cppCast "\<reinterpret_pointer_cast\s*$" 75 syn match cppFloat display contained "\<0[Xx]\x*\.\x\+p[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" 76 syn match cppFloat display contained "\<0[Xx]\x\+\.\=p[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>" 77 78 " TODO: push this up to c.vim if/when supported in C23 79 syn match cppCharacter "u8'[^\\]'" 80 syn match cppCharacter "u8'[^']*'" contains=cSpecial 81 if exists("c_gnu") 82 syn match cppSpecialError "u8'\\[^'\"?\\abefnrtv]'" 83 syn match cppSpecialCharacter "u8'\\['\"?\\abefnrtv]'" 84 else 85 syn match cppSpecialError "u8'\\[^'\"?\\abfnrtv]'" 86 syn match cppSpecialCharacter "u8'\\['\"?\\abfnrtv]'" 87 endif 88 syn match cppSpecialCharacter display "u8'\\\o\{1,3}'" 89 syn match cppSpecialCharacter display "u8'\\x\x\+'" 90 91 endif 92 93 " C++ 20 extensions 94 if !exists("cpp_no_cpp20") 95 syn match cppNumber display contained "\<0\(y\|d\)\>" 96 syn match cppNumber display contained "\<[1-9]\('\=\d\+\)*\(y\|d\)\>" 97 syn match cppNumber display contained "\<0\o\+\(y\|d\)\>" 98 syn match cppNumber display contained "\<0[Bb][01]\('\=[01]\+\)*\(y\|d\)\>" 99 syn match cppNumber display contained "\<0[Xx]\x\('\=\x\+\)*\(y\|d\)\>" 100 syn keyword cppStatement co_await co_return co_yield requires 101 syn keyword cppStorageClass consteval constinit 102 syn keyword cppStructure concept 103 syn keyword cppType char8_t 104 syn keyword cppModule import module export 105 endif 106 107 " The minimum and maximum operators in GNU C++ 108 syn match cppMinMax "[<>]?" 109 110 " Default highlighting 111 hi def link cppAccess cppStatement 112 hi def link cppCast cppStatement 113 hi def link cppExceptions Exception 114 hi def link cppOperator Operator 115 hi def link cppStatement Statement 116 hi def link cppModifier Type 117 hi def link cppType Type 118 hi def link cppStorageClass StorageClass 119 hi def link cppStructure Structure 120 hi def link cppBoolean Boolean 121 hi def link cppCharacter cCharacter 122 hi def link cppSpecialCharacter cSpecialCharacter 123 hi def link cppSpecialError cSpecialError 124 hi def link cppConstant Constant 125 hi def link cppRawStringDelimiter Delimiter 126 hi def link cppRawString String 127 hi def link cppString String 128 hi def link cppNumber Number 129 hi def link cppFloat Number 130 hi def link cppModule Include 131 132 let b:current_syntax = "cpp" 133 134 " vim: ts=8