Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 564
Karl Avatar asked Aug 03 '09 21:08

Karl


2 Answers

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 
like image 180
Jess Telford Avatar answered Sep 28 '22 05:09

Jess Telford


" Assuming Vim 7 (full version) is installed, "   adding the following to your ~/.vimrc should work.  filetype plugin on au FileType php set omnifunc=phpcomplete#CompletePHP  " You might also find this useful " PHP Generated Code Highlights (HTML & SQL)                                                let php_sql_query=1                                                                                         let php_htmlInStrings=1  " Hope this helps! 

(via http://www.linuxquestions.org/questions/linux-software-2/vim-omin-completion-for-php-621940/#post3155311)

like image 39
ax. Avatar answered Sep 28 '22 04:09

ax.