Auto-complete PHP code in Vim

Vim is able to auto-complete syntax for some of the most popular programming languages, but it's not enabled by default.

While in command mode, enter the following

:set omnifunc=phpcomplete#CompletePHP

To start using PHP auto completion, press the Ctrl + x followed by Ctrl + o keys while writing some PHP functions.

Below is an example screenshot when pressing Ctrl + x followed by Ctrl + o after typing dat

Do note the function description provided at the top of the screen.

Automatically enable PHP autocomplete for every PHP file

To enable PHP autocomplete every time you open a PHP file, add this to your ~/.vimrc;

autocmd FileType php set omnifunc=phpcomplete#CompletePHP

Sign up for Vim Masterclass and many other great courses on Udemy to learn more.

Vim Masterclass

Mastering the vi and Vim Editors on the Linux, Unix, Mac, and Windows Operating Systems!

Written by Mohd Shakir Zakaria. Last updated on 2019-02-12