問題描述
我正在嘗試在 Vim 中正確地獲得 PHP 自動完成功能.現(xiàn)在當我做一個 $blog = new Blog();$blog->
然后點擊CTRL+X CTRL+O
我希望omnicompletion 返回Blog
類中的所有函數(shù).
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
.
相反,它返回整個項目的所有函數(shù).我已經(jīng)為我的項目構(gòu)建了 ctags,如下所示:ctags -R *
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 的回答 通過在您使用 omnicomplete 的行之前添加諸如 /* @var $myVar myClass */
之類的注釋來指出解決方法,但是這很麻煩,而且暫時需要寫注釋,你也可以自己寫函數(shù)名.
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.
這是一個 Vim 腳本:phpComplete
It is a Vim script: phpComplete
你仍然需要為你的類生成一個標簽文件,但你可以在文件中使用 omni complete,就像這樣(從腳本頁面的描述中修改);
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);
此補丁允許進行文件內(nèi)檢查,因此您不需要注釋.
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
這篇關(guān)于Vim PHP 全能完成的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!