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