Vim PHP omni completion


I'm trying to get PHP autocompletion right in Vim. Right now when I do a $blog = new Blog(); $blog-> and then hit CTRL+X CTRL+O I'd expect omnicompletion to return all the functions in the class Blog.

Instead, it returns all functions for the entire project. I've built ctags for my project like so: ctags -R *

Is there any way to make the autocompletion context-aware?

5/5/2012 9:54:06 AM

catchmeifyoutry's answer points out a work-around by adding a comment such as /* @var $myVar myClass */ immediately before the line on which you use omnicomplete, however this is cumbersome and for the time it takes to write the comment, you may as well have written the function name yourself.

Solution: phpComplete

It is a Vim script: phpComplete

You will still need a tags file generated for your classes, but you can then use omni complete within the file, like so (modified from the description on the script's page);

This patch allows for in-file checking so you don't need the comment.

$blog = new Blog;
$blog->Blah(); // <-- complete without comment 

It also allows support for singleton instantiations:

$instance = Class::getInstance(); 
$instance->completeMe(); // sweet completion
5/23/2017 12:25:02 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow