php annotations syntax : syntax highlighting for php annotations
| script karma
Downloaded by 182
Comments, bugs, improvements
script versions (upload new version)
|Small script to add annotations highlighting to php syntax.
Annotations within comments are highlighted with pre-defined SpecialComment highlight group name (used for example for backslash escapes in string literals).
Annotations highlighting is useful when they are used as more then documentation blocks or comments, like for actual program flow control, as doctrine ORM is using them. Some people might consider such use of comments, as part of the program logic, to be bad practice, and the script author here tends to agree. But this is how annotation syntax works in php, so this is how they are used anyway. Doctrine ORM tends to look for annotations anywhere within a comment line, but only annotations that start at the beginning of a comment line will be highlighted here.
php annotations use docBlock comments (documentation comment blocks, beginning with /** and ending with */) and the main use case for this syntax script is to contrast the regular annotations with any of them accidentally placed within simple comments, where they have no effect, so you can spot them easier.
If you find the highlighting annoying with your color scheme or with your annotations usage in php, you may use a command like
:highlight link SpecialComment Number
to change the appearance (you can replace Number above with some other highlight group you may like), or you can disable the script with the
:let g:php_annotations_syntax = 0
command in your .vimrc file.
If and when the main php syntax file provided with Vim ever gets updated to include annotations, this script will become obsolete.
That main file is getting quite old with all new php functions and classes added by every new php version; currently there are several newer alternatives on the Vim scripts site, but they like to replace, instead of extend, the main file provided by the distribution.
|Copy the provided script file php.vim into your
If you already have some another php.vim file (perhaps your own) in your after/syntax directory, you can create an after/syntax/php/ directory to contain them both.
Click on the package to download.
ip used for rating: 188.8.131.52
||Using the more specific SpecialComment highlight group instead of Special for the annotations.
||Some support for one-line docBlock comments (like /** @var ClassName $myObj */).
Highlighting for strings, numbers and some operators and punctuation within the annotations.