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
Support ------- [✔] Composer detected - faster class location and more features! [✔] Git detected - enables faster refactorings in your repository scope! Config files ------------ [✔] /home/daniel/www/phpactor/phpactor/.phpactor.yml [✔] /home/daniel/.config/phpactor/phpactor.yml [✘] /etc/xdg/phpactor/phpactor.yml
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:
If you are feeling dangerous, you may choose to track the
by specifying a branch name in your
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"
The plugin has some configuration options:
let g:phpactorPhpBin = 'php' let g:phpactorBranch = 'master' let g:phpactorOmniError = v:false
g:phpactorPhpBin: PHP executable to use.
g:phpactorBranch: Phpactor branch (default is
developfor bleeding edge).
g:phpactorOmniError: Set to
v:trueto enable useful error messages when completion is invoked.
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: