(Move categories to tip template) |
(Change <tt> to <code>, perhaps also minor tweak.) |
||
(5 intermediate revisions by 5 users not shown) | |||
Line 3: | Line 3: | ||
|previous=640 |
|previous=640 |
||
|next=642 |
|next=642 |
||
− | |created= |
+ | |created=2004 |
|complexity=basic |
|complexity=basic |
||
|author=Olivier Teuliere |
|author=Olivier Teuliere |
||
Line 9: | Line 9: | ||
|rating=30/15 |
|rating=30/15 |
||
|category1=C++ |
|category1=C++ |
||
− | |category2= |
+ | |category2=Syntax |
}} |
}} |
||
When editing big cpp files, it can be very convenient to highlight the method name (the part after "::") in a method definition. |
When editing big cpp files, it can be very convenient to highlight the method name (the part after "::") in a method definition. |
||
I use the following function in my vimrc: |
I use the following function in my vimrc: |
||
− | |||
<pre> |
<pre> |
||
" Add highlighting for function definition in C++ |
" Add highlighting for function definition in C++ |
||
Line 24: | Line 23: | ||
I have another line to call this function automatically when editing a C++ file: |
I have another line to call this function automatically when editing a C++ file: |
||
− | |||
<pre> |
<pre> |
||
autocmd Syntax cpp call EnhanceCppSyntax() |
autocmd Syntax cpp call EnhanceCppSyntax() |
||
</pre> |
</pre> |
||
− | This doesn't work in all cases (for instance, it doesn't highlight constructors using an initialization list on the same line) but it shouldn't highlight function calls (such as < |
+ | This doesn't work in all cases (for instance, it doesn't highlight constructors using an initialization list on the same line) but it shouldn't highlight function calls (such as <code>MyClass::MyStaticMethod( int foo );</code> ) |
+ | |||
+ | ==See also== |
||
+ | * [[Jump between methods in C++]] |
||
==Comments== |
==Comments== |
Latest revision as of 05:40, 13 July 2012
Tip 641 Printable Monobook Previous Next
created 2004 · complexity basic · author Olivier Teuliere · version 6.0
When editing big cpp files, it can be very convenient to highlight the method name (the part after "::") in a method definition.
I use the following function in my vimrc:
" Add highlighting for function definition in C++ function! EnhanceCppSyntax() syn match cppFuncDef "::\~\?\zs\h\w*\ze([^)]*\()\s*\(const\)\?\)\?$" hi def link cppFuncDef Special endfunction
I have another line to call this function automatically when editing a C++ file:
autocmd Syntax cpp call EnhanceCppSyntax()
This doesn't work in all cases (for instance, it doesn't highlight constructors using an initialization list on the same line) but it shouldn't highlight function calls (such as MyClass::MyStaticMethod( int foo );
)
See also[]
Comments[]
To further facilitate adding user-defined extensions to existing syntax files, you can use a ".vim/after/syntax/" directory. See :help mysyntaxfile-add.