History
Article Edit this page Discussion

Highlighting of method names in the definition

From Vim Tips Wiki

(Redirected from VimTip641)
Jump to: navigation, search

Tip 641 Previous Next Created: January 21, 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 ); )

[edit] Comments

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


Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto Wiki
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Highlighting of method names in the definition"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation