Vim PHP omni completion(Vim PHP 全能完成)
问题描述
我正在尝试在 Vim 中正确地获得 PHP 自动完成功能.现在当我做一个 $blog = new Blog();$blog-> 然后点击CTRL+X CTRL+O 我希望omnicompletion 返回Blog 类中的所有函数.
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.
相反,它返回整个项目的所有函数.我已经为我的项目构建了 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 */ 之类的注释来指出解决方法,但是这很麻烦,而且暂时需要写注释,你也可以自己写函数名.
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);
此补丁允许进行文件内检查,因此您不需要注释.
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
这篇关于Vim PHP 全能完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Vim PHP 全能完成
基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
