From a7630ace5571f9401e46312dcfab5f5e849c406a Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Sun, 4 Sep 2016 21:46:46 +0100 Subject: [PATCH] Improve C/C++ syntax highlighting --- after/syntax/c.vim | 35 +++++++++++++++++++++++++++++++++++ after/syntax/cpp.vim | 28 ++++++++++++---------------- 2 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 after/syntax/c.vim diff --git a/after/syntax/c.vim b/after/syntax/c.vim new file mode 100644 index 0000000..50c7f56 --- /dev/null +++ b/after/syntax/c.vim @@ -0,0 +1,35 @@ +" Language: C +" Description: Additional C syntax file. +" Author: Kenneth Benzie (Benie) +" Last Modified: September 04, 2016 + +" Match delimiter expressions: (expr) {expr} : ; +" ^ ^ ^ ^ ^ ^ +syn match cDelimiter '[()\[\]{}:;]' +" Match single character operators, ordering within the [] is important +syn match cOperator '[\*=\.\^\~+-,&|!%]' +" Match single character operators if they are surrounded by white space: / < > +" ^ ^ ^ +syn match cOperator '\(\s\zs\/\s\ze\|\s\zs<\s\ze\|\s\zs>\s\ze\)' +" Match multi character operators +syn match cOperator '\(+=\|-=\|\*=\|/=\|%=\|\ˆ=\|&=\||=\|<<\|>>\|>>=\)' +syn match cOperator '\(<<=\|==\|!=\|<=\|>=\|&&\|||\|++\|--\|->\*\|->\)' +" Match function expressions: expr() +" ^^^^ +syn match cFunction '\w[A-Za-z0-9_]*\ze\s*(' +" Match label expressions: expr: +" ^^^^ +syn match cLabel '^\s*\w[A-Za-z0-9_]\+\ze::\@!' contains=cppAccess + +" Match Doxygen comments +let g:c_enable_doxygen_highlights = get(g:, 'c_enable_doxygen_highlights', 1) +if g:c_enable_doxygen_highlights + syn region cDoxygen oneline matchgroup=cComment start='\/\/\/\s*@brief\s\+' end='$' + syn region cDoxygen oneline matchgroup=cComment start='\/\/\/\s*@tparam\s\+' end='\(\s.*$\|$\)' + syn region cDoxygen oneline matchgroup=cComment start='\/\/\/\s*@param\(\[\(\|in\|out\|inout\)\]\)\=\s\+' end='\(\s.*$\|$\)' + hi default link cDoxygen SpecialComment +endif + +" Define additional highlight groups +hi default link cDelimiter Delimiter +hi default link cFunction Function diff --git a/after/syntax/cpp.vim b/after/syntax/cpp.vim index e0fb08b..aee6ac0 100644 --- a/after/syntax/cpp.vim +++ b/after/syntax/cpp.vim @@ -1,30 +1,26 @@ -" File: cpp.vim " Language: C++ " Description: Additional C++ syntax file. " Author: Kenneth Benzie (Benie) k.benzie83@gmail.com -" Last Modified: September 02, 2016 +" Last Modified: September 04, 2016 -" Match delimiter expressions: , (expr) {expr} ex::pr -" ^ ^ ^ ^ ^ ^ ^^ -syn match cppDelimiter '\([()\[\]{}<>]\|::\)' +" Match delimiter expressions: , ex::pr +" ^ ^ ^^ +syn match cppDelimiter '\(<\|>\|::\)' " Match keyword logic operators -syn keyword cppOperator and and_eq bitand bitor compl -syn keyword cppOperator not not_eq or or_eq xor xor_eq -" Match single character operators, ordering within the [] is important -syn match cppOperator '[\*=\.\^\~+-,;&|!%]' +syn keyword cppOperator and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq " Match single character operators if they are surrounded by white space: / < > " ^ ^ ^ syn match cppOperator '\(\s\zs\/\s\ze\|\s\zs<\s\ze\|\s\zs>\s\ze\)' -" Match multi character operators -syn match cppOperator '\(+=\|-=\|\*=\|/=\|%=\|\ˆ=\|&=\||=\|<<\|>>\|>>=\)' -syn match cppOperator '\(<<=\|==\|!=\|<=\|>=\|&&\|||\|++\|--\|->\*\|->\)' -" Match function expressions: foo() -" ^^^ -syn match cppFunction '\w[A-Za-z0-9_]*\ze\s*(' " Match nested namespace expressions: expr:: " ^^^^ syn match cppStorageClass '\w[A-Za-z0-9_]*\ze::' +" " Match multi character operators, override cppDelimiter matches for < > +" " ^ ^ +syn match cppOperator '\(<<\|>>\|>>=\|<<=\|<=\|>=\|->\*\|->\)' " Define additional highlight groups hi default link cppDelimiter Delimiter -hi default link cppFunction Function + +" Override default highlight groups +hi link cppCast Operator +hi link cppModifier Statement