PHPCD (PHP Completion Daemon) is another PHP completion engine for Vim/NeoVim.
PHPCD is based on phpcomplete.vim but is faster and smarter.
While phpcomplete.vim uses the tags file to fetch the context info, PHPCD uses PHP's Reflection mechanism to fetch the context info, and this is why PHPCD is faster. All the phpcomplete VimL code related the tags file has been droped and reimplemented.
PHPCD consists of two parts. On part is written in VimL (mainly based on phpcomplete.vim), and the other in PHP. The communication between the VimL part and the PHP part relies on NeoVim's MsgPack-RPC mechanism. This is why NeoVim is needed. Both NeoVim and Vim 8.0+ are supported now. Thanks to NeoVims's MsgPack-RPC and Vim's Channel/Job mechanism.
- Fast, Lightweight, Powerful, Smart
- Correct restriction of static or standard methods based on context (show only static methods with
::
and only standard with->
) - Real support for
self::
,static::
,parent::
and$this->
with the aforementioned context restriction - Better class detection
- Recognize
/* @var $yourvar YourClass */
、/* @var YourClass $yourvar */
type mark comments - Recognize
$instance = new Class;
class instantiations - Recognize
(new Class)->
class instantiations - Recognize
$date = DateTime::createFromFormat(...)
built-in class return types - Recognize both parameter type hinting and return hinting in function prototypes
- Recognize types in
@param
lines in function docblocks - Recognize types in
@return
lines in function docblocks - Recognize
$instance = Class::foo()->bar();
method call chain return type - Recognize array of objects via docblock like
$foo[42]->
or for variables created inforeach
- Recognize property type by assignment in
__construct
- Recognize property type by setter
- Recognize
- Namespace autocompletion (you first need to do
composer dump-autoload -o
) - Displays docblock info in the preview for methods and properties
- Support built-in class support with constants, methods and properties
- Enhanced jump-to-definition on ctrl+]
PHP 5.6+The master branch only support php7. If you have to use php5, please use the php5 branch.- PCNTL Extension
- Msgpack 0.5.7+(for NeoVim) Extension or JSON(for Vim 7.4+) Extension
Composer Project
We recommend you use Vim-Plug to manage your vim plugins.
With Vim-Plug installed, put the following lines in your vimrc:
Plug 'lvht/phpcd.vim', { 'for': 'php', 'do': 'composer install' }
And then execute :PlugInstall
in the command mode.
If you install phpcd manually, you need run composer install
in the phpcd.vim root directory.
If you using the deoplete, you can add the following lines to you init.vim
call deoplete#custom#option('ignore_sources', {'php': ['omni']})
The phpcd will work with deoplete happily.
However if you are experiencing problems with deoplete you can disable the phpcd source.
call deoplete#custom#option('ignore_sources', {'php': ['phpcd', 'omni']})
First, in the project directory, run
The composer is not required any more. However, if you want to let phpcd work with your project, you must to make a autoload file for your project.composer install
to install all the dependent packages and generate the autoload file.
If you use composer, composer will make the vendor/autoload.php
. phpcd will use vendor/autoload.php
automatically.
If your project does not use composer but have a path/to/autoload_file.php
, you need to create a .phpcd.vim file in your project root path, and let it reads
let g:phpcd_autoload_path = 'path/to/autoload_file.php'
And phpcd will use the g:phpcd_autoload_path
to load your class.
The default PHP command used to run PHP parts of daemon is simply php
. You may override it by assigning g:phpcd_php_cli_executable
another value in your vimrc
, for example:
let g:phpcd_php_cli_executable = 'php7.0'
Use Ctrl+xCtrl+o to complete and use ctrl+] to go to the definition.
If you use neosnippet, you may like to set g:phpcd_disable_modifier
to 0
.
Good luck :)