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

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 alsoEdit


To further facilitate adding user-defined extensions to existing syntax files, you can use a ".vim/after/syntax/" directory. See :help mysyntaxfile-add.

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.