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