sponsor Vim development Vim logo Vim Book Ad

php annotations syntax : syntax highlighting for php annotations

 script karma  Rating 0/0, Downloaded by 298    Comments, bugs, improvements  Vim wiki

created by
Timothy Madden
 
script type
syntax
 
description
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.
 
install details
Copy the provided script file php.vim into your
        ~/.vim/after/syntax/                                                        (Linux/Unix)
or
         %USERPROFILE%\vimfiles\after\syntax\         (Windows)
directory.

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.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
php.vim 0.3 2013-05-01 7.0 Timothy Madden Using the more specific SpecialComment highlight group instead of Special for the annotations.
php.vim 0.2 2013-05-01 7.0 Timothy Madden Some support for one-line docBlock comments (like /** @var ClassName $myObj */).
Highlighting for strings, numbers and some operators and punctuation within the annotations.
php.vim 0.1 2013-04-29 7.0 Timothy Madden Initial upload
ip used for rating: 54.198.94.76

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
SourceForge.net Logo