Phpactor VIM Plugin
Install Phpactor using your favorite VIM package manager, I am using Vundle.
Add the plugin to your
Then in VIM:
Now you will need to install the Phpactor dependencies with composer:
$ cd ~/.vim/bundle/phpactor $ composer install
or using nvim, do the above where it counts.
Now issue the following command
✔ Composer detected - faster class location and more features! ✔ Git detected - enables faster refactorings in your repository scope!
Phpactor works best with Composer - but much functionality including auto-completion can still work (sometimes slowly depending on project size).
Updating Phpactor from VIM is easy:
The Phpactor plugin will not automatically assume any shortcuts, copy
the following configuration into your
" Include use statement nmap <Leader>u :call phpactor#UseAdd()<CR> " Invoke the context menu nmap <Leader>mm :call phpactor#ContextMenu()<CR> " Goto definition of class or class member under the cursor nmap <Leader>o :call phpactor#GotoDefinition()<CR> " Transform the classes in the current file nmap <Leader>tt :call phpactor#Transform()<CR> " Generate a new class (replacing the current file) nmap <Leader>cc :call phpactor#ClassNew()<CR> " Extract method from selection vmap <silent><Leader>em :<C-U>call phpactor#ExtractMethod()<CR>
See the Refactorings chapter for more functions you can map shortcuts to.
Phpactor requires at least PHP 7.0. If you use a different version of PHP
locally, you may need to target a new version of PHP - add the following to
.vimrc to change the PHP binary:
let g:phpactorPhpBin = "/usr/bin/local/php6.0"
Omni-completion (Screenshot) is VIM's built-in auto-completion mechanism.
Add the following to your
.vimrc in order to use Phpactor for omni-completion (for PHP files):
autocmd FileType php setlocal omnifunc=phpactor#Complete
To invoke omni complete in insert mode
The Omni-Complete method provides feedback messages when it cannot complete something. This information is useful. Other completion mehanisms may not provide this information.
Always enable omni-completion. If another mechanism is failing to complete, invoke omni-complete to find out why.
Neovim Completion Manager
The context menu is the main point of contact with Phpactor. Invoke it on any class, member, variable, method call, or anything really.
If you move over a method and invoke the context menu with
:call phpactor#ContextMenu() (or with
<Leader>mm as per the configuration above) you
should see something like the following:
Method "execute": [r]eplace_references, (f)ind_references, (g)enerate_method, g(o)to_definition: