blob: 53b6a513f208970b10e3af9e5328065d43d00f0d [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 Moolenaar95a9dd12019-12-19 22:12:03 +01005" Last Change: 2019 Dec 18
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
12" Read the C syntax to start with
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020013runtime! syntax/c.vim
14unlet b:current_syntax
Bram Moolenaar071d4272004-06-13 20:20:40 +000015
Bram Moolenaarac7bd632013-03-19 11:35:58 +010016" C++ extensions
Bram Moolenaar071d4272004-06-13 20:20:40 +000017syn keyword cppStatement new delete this friend using
18syn keyword cppAccess public protected private
Bram Moolenaarb4ff5182015-11-10 21:15:48 +010019syn keyword cppModifier inline virtual explicit export
20syn keyword cppType bool wchar_t
Bram Moolenaar071d4272004-06-13 20:20:40 +000021syn keyword cppExceptions throw try catch
22syn keyword cppOperator operator typeid
23syn keyword cppOperator and bitor or xor compl bitand and_eq or_eq xor_eq not not_eq
24syn match cppCast "\<\(const\|static\|dynamic\|reinterpret\)_cast\s*<"me=e-1
25syn match cppCast "\<\(const\|static\|dynamic\|reinterpret\)_cast\s*$"
26syn keyword cppStorageClass mutable
27syn keyword cppStructure class typename template namespace
Bram Moolenaar071d4272004-06-13 20:20:40 +000028syn keyword cppBoolean true false
Bram Moolenaard8b77f72015-03-05 21:21:19 +010029syn keyword cppConstant __cplusplus
Bram Moolenaar071d4272004-06-13 20:20:40 +000030
Bram Moolenaarac7bd632013-03-19 11:35:58 +010031" C++ 11 extensions
32if !exists("cpp_no_cpp11")
Bram Moolenaarb4ff5182015-11-10 21:15:48 +010033 syn keyword cppModifier override final
Bram Moolenaarb4ada792016-10-30 21:55:26 +010034 syn keyword cppType nullptr_t auto
Bram Moolenaarac7bd632013-03-19 11:35:58 +010035 syn keyword cppExceptions noexcept
Bram Moolenaard8b77f72015-03-05 21:21:19 +010036 syn keyword cppStorageClass constexpr decltype thread_local
Bram Moolenaarac7bd632013-03-19 11:35:58 +010037 syn keyword cppConstant nullptr
Bram Moolenaard8b77f72015-03-05 21:21:19 +010038 syn keyword cppConstant ATOMIC_FLAG_INIT ATOMIC_VAR_INIT
39 syn keyword cppConstant ATOMIC_BOOL_LOCK_FREE ATOMIC_CHAR_LOCK_FREE
40 syn keyword cppConstant ATOMIC_CHAR16_T_LOCK_FREE ATOMIC_CHAR32_T_LOCK_FREE
41 syn keyword cppConstant ATOMIC_WCHAR_T_LOCK_FREE ATOMIC_SHORT_LOCK_FREE
42 syn keyword cppConstant ATOMIC_INT_LOCK_FREE ATOMIC_LONG_LOCK_FREE
43 syn keyword cppConstant ATOMIC_LLONG_LOCK_FREE ATOMIC_POINTER_LOCK_FREE
Bram Moolenaarf2571c62015-06-09 19:44:55 +020044 syn region cppRawString matchgroup=cppRawStringDelimiter start=+\%(u8\|[uLU]\)\=R"\z([[:alnum:]_{}[\]#<>%:;.?*\+\-/\^&|~!=,"']\{,16}\)(+ end=+)\z1"+ contains=@Spell
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010045 syn match cppCast "\<\(const\|static\|dynamic\)_pointer_cast\s*<"me=e-1
46 syn match cppCast "\<\(const\|static\|dynamic\)_pointer_cast\s*$"
Bram Moolenaarac7bd632013-03-19 11:35:58 +010047endif
48
Bram Moolenaarb4ff5182015-11-10 21:15:48 +010049" C++ 14 extensions
50if !exists("cpp_no_cpp14")
Bram Moolenaarb4ada792016-10-30 21:55:26 +010051 syn case ignore
52 syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\(u\=l\{0,2}\|ll\=u\)\>"
Bram Moolenaar6aa8cea2017-06-05 14:44:35 +020053 syn match cppNumber display "\<[1-9]\('\=\d\+\)*\(u\=l\{0,2}\|ll\=u\)\>" contains=cFloat
Bram Moolenaarb4ada792016-10-30 21:55:26 +010054 syn match cppNumber display "\<0x\x\('\=\x\+\)*\(u\=l\{0,2}\|ll\=u\)\>"
55 syn case match
Bram Moolenaarb4ff5182015-11-10 21:15:48 +010056endif
57
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010058" C++ 20 extensions
59if !exists("cpp_no_cpp20")
60 syn keyword cppStatement co_await co_return co_yield requires
61 syn keyword cppStorageClass consteval constinit
62 syn keyword cppStructure concept
63 syn keyword cppType char8_t
64 syn keyword cppModule import module export
65endif
66
67" C++ 17 extensions
68if !exists("cpp_no_cpp17")
69 syn match cppCast "\<reinterpret_pointer_cast\s*<"me=e-1
70 syn match cppCast "\<reinterpret_pointer_cast\s*$"
71endif
72
Bram Moolenaar071d4272004-06-13 20:20:40 +000073" The minimum and maximum operators in GNU C++
74syn match cppMinMax "[<>]?"
75
76" Default highlighting
Bram Moolenaarf37506f2016-08-31 22:22:10 +020077hi def link cppAccess cppStatement
78hi def link cppCast cppStatement
79hi def link cppExceptions Exception
80hi def link cppOperator Operator
81hi def link cppStatement Statement
82hi def link cppModifier Type
83hi def link cppType Type
84hi def link cppStorageClass StorageClass
85hi def link cppStructure Structure
86hi def link cppBoolean Boolean
87hi def link cppConstant Constant
88hi def link cppRawStringDelimiter Delimiter
89hi def link cppRawString String
90hi def link cppNumber Number
Bram Moolenaar95a9dd12019-12-19 22:12:03 +010091hi def link cppModule Include
Bram Moolenaar071d4272004-06-13 20:20:40 +000092
93let b:current_syntax = "cpp"
94
95" vim: ts=8