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?
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.
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
" 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With