currentMenu: vim-plugin

Phpactor VIM Plugin


Install Phpactor using your favorite VIM package manager, I am using Vundle. Add the plugin to your .vimrc:

Plugin 'phpactor/phpactor'

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.

Make a Pull Request to improve this installation procedure!

Now issue the following command :call phpactor#Status():

✔ 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:

:call phpactor#Update()
Note that if the update included changes to the VIM plugin you will currently need to either re-source (`:source ~/path/to/phpactor/plugin/phpactor.vim`) the plugin or reload VIM (pull requests are open!).

Keyboard Mappings

The Phpactor plugin will not automatically assume any shortcuts, copy the following configuration into your .vimrc:

" 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 your .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 <C-x><C-o> (ctrl-x then ctrl-o). See :help compl-omni.

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

If you are using Neovim with the Neovim Completion Manager you should certainly install ncm-phpactor to benefit from great asynchronous complete-as-you-type auto-completion:

Context Menu

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: