blob: ed38913f291b43717b1ace5ab36ab70b34a6de0a [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: C++
Bram Moolenaard8b77f72015-03-05 21:21:19 +01003" Current Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp)
Bram Moolenaarac7bd632013-03-19 11:35:58 +01004" Previous Maintainer: Ken Shan <ccshan@post.harvard.edu>
Bram Moolenaar98a29d02021-01-18 19:55:44 +01005" Last Change: 2021 Jan 12
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
Bram Moolenaar89bcfda2016-08-30 23:26:57 +02007" quit when a syntax file was already loaded
8if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +00009 finish
10endif
11
Bram Moolenaar98a29d02021-01-18 19:55:44 +010012" inform C syntax that the file was included from cpp.vim
13let b:filetype_in_cpp_family = 1
14
Bram Moolenaar071d4272004-06-13 20:20:40 +000015" Read the C syntax to start with
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020016runtime! syntax/c.vim
17unlet b:current_syntax
Bram Moolenaar071d4272004-06-13 20:20:40 +000018
Bram Moolenaarac7bd632013-03-19 11:35:58 +010019" C++ extensions
Bram Moolenaar071d4272004-06-13 20:20:40 +000020syn keyword cppStatement new delete this friend using
21syn keyword cppAccess public protected private
Bram Moolenaarb4ff5182015-11-10 21:15:48 +010022syn keyword cppModifier inline virtual explicit export
23syn keyword cppType bool wchar_t
Bram Moolenaar071d4272004-06-13 20:20:40 +000024syn 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
Bram Moolenaar071d4272004-06-13 20:20:40 +000031syn keyword cppBoolean true false
Bram Moolenaard8b77f72015-03-05 21:21:19 +010032syn keyword cppConstant __cplusplus
Bram Moolenaar071d4272004-06-13 20:20:40 +000033
Bram Moolenaarac7bd632013-03-19 11:35:58 +010034" C++ 11 extensions
35if !exists("cpp_no_cpp11")
Bram Moolenaarb4ff5182015-11-10 21:15:48 +010036 syn keyword cppModifier override final
Bram Moolenaarb4ada792016-10-30 21:55:26 +010037 syn keyword cppType nullptr_t auto
Bram Moolenaarac7bd632013-03-19 11:35:58 +010038 syn keyword cppExceptions noexcept
Bram Moolenaard8b77f72015-03-05 21:21:19 +010039 syn keyword cppStorageClass constexpr decltype thread_local
Bram Moolenaarac7bd632013-03-19 11:35:58 +010040 syn keyword cppConstant nullptr
Bram Moolenaard8b77f72015-03-05 21:21:19 +010041 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
Bram Moolenaarf2571c62015-06-09 19:44:55 +020047 syn region cppRawString matchgroup=cppRawStringDelimiter start=+\%(u8\|[uLU]\)\=R"\z([[:alnum:]_{}[\]#<>%:;.?*\+\-/\^&|~!=,"']\{,16}\)(+ end=+)\z1"+ contains=@Spell
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010048 syn match cppCast "\<\(const\|static\|dynamic\)_pointer_cast\s*<"me=e-1
49 syn match cppCast "\<\(const\|static\|dynamic\)_pointer_cast\s*$"
Bram Moolenaarac7bd632013-03-19 11:35:58 +010050endif
51
Bram Moolenaarb4ff5182015-11-10 21:15:48 +010052" C++ 14 extensions
53if !exists("cpp_no_cpp14")
Bram Moolenaarb4ada792016-10-30 21:55:26 +010054 syn case ignore
55 syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\(u\=l\{0,2}\|ll\=u\)\>"
Bram Moolenaar6aa8cea2017-06-05 14:44:35 +020056 syn match cppNumber display "\<[1-9]\('\=\d\+\)*\(u\=l\{0,2}\|ll\=u\)\>" contains=cFloat
Bram Moolenaarb4ada792016-10-30 21:55:26 +010057 syn match cppNumber display "\<0x\x\('\=\x\+\)*\(u\=l\{0,2}\|ll\=u\)\>"
58 syn case match
Bram Moolenaarb4ff5182015-11-10 21:15:48 +010059endif
60
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010061" C++ 20 extensions
62if !exists("cpp_no_cpp20")
63 syn keyword cppStatement co_await co_return co_yield requires
64 syn keyword cppStorageClass consteval constinit
65 syn keyword cppStructure concept
66 syn keyword cppType char8_t
67 syn keyword cppModule import module export
68endif
69
70" C++ 17 extensions
71if !exists("cpp_no_cpp17")
72 syn match cppCast "\<reinterpret_pointer_cast\s*<"me=e-1
73 syn match cppCast "\<reinterpret_pointer_cast\s*$"
74endif
75
Bram Moolenaar071d4272004-06-13 20:20:40 +000076" The minimum and maximum operators in GNU C++
77syn match cppMinMax "[<>]?"
78
79" Default highlighting
Bram Moolenaarf37506f2016-08-31 22:22:10 +020080hi def link cppAccess cppStatement
81hi def link cppCast cppStatement
82hi def link cppExceptions Exception
83hi def link cppOperator Operator
84hi def link cppStatement Statement
85hi def link cppModifier Type
86hi def link cppType Type
87hi def link cppStorageClass StorageClass
88hi def link cppStructure Structure
89hi def link cppBoolean Boolean
90hi def link cppConstant Constant
91hi def link cppRawStringDelimiter Delimiter
92hi def link cppRawString String
93hi def link cppNumber Number
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010094hi def link cppModule Include
Bram Moolenaar071d4272004-06-13 20:20:40 +000095
96let b:current_syntax = "cpp"
97
98" vim: ts=8