Is it possible to auto format PHP in Sublime Text 2?

Junior Mayhé picture Junior Mayhé · May 17, 2012 · Viewed 60.8k times · Source

In Sublime Text 2, I am trying to type the code and have auto format command to rearrange and auto indent source code. If it is not possible to have a automatic formatter, would be nice to have a shortcut command to do it.

I am searching for something else besides the built-in "Reindent" option and the hard-to-make-work "PHP Beautifier" plugin.

I would like to know if someone found any nice auto formatter for PHP: any formatter that won't mess our PHP code. JSFormat seems to be not useful.

Is there any easy to "install and use" plugin?

Answer

Vukasin picture Vukasin · Mar 9, 2013

PHPTidy is definitely good choice for PHP code formatting in SublimeText2.

You need to install package control package to enable you to install packaged in sublime text: link.

  1. ctrl+shift+p -> type -> Package Control: Install Package

  2. search for phpTidy -> hit enter

that is it - now you can format your code in WordPress coding convention.

How to format you code:

  1. ctrl+shift+p -> type -> tidy -> Hit Enter
  2. ctrl+alt+t

Hope this help.