Post

Format PHP with Vim using phpcs codesniffer

How to use squizlabs to auto format PHP code in Vim.

If you’re using neovim to edit php and you want the php to format itself then you will need some extra thing’s installed to make this work.

install squizlabs php code sniffer using composer into your project directory

1
composer global require "squizlabs/php_codesniffer=\*"

visit the repo for all the information

install plugin in vim

I use ‘vim plug’ to install plugins

visit the repo for all the information

format php code

In the vim buffer, run the command to format the php. You should see some indenting happen.

1
:Neoformat

php code will also auto format as you move code around the document. Please note Html auto formatting does not work.

This post is licensed under CC BY 4.0 by the author.