Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 553
Junior Mayhé Avatar asked May 17 '12 00:05

Junior Mayhé


People also ask

Can Sublime Text be used for PHP?

The most significantly PHP-focused package for Sublime Text is called Sublime PHP Companion. Like most packages, it contains a series of actions you can perform.

How do I beautify the code in Sublime Text?

Beautify on Save sublime-settings : Ctrl+Shift+P or Cmd+Shift+P in Linux/Windows/OS X.

How do I format a PHP file?

Add right click menu option for Format HTML in PHP. Add keybind Ctrl + Alt + F to format HTML in a PHP file.


2 Answers

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.

like image 82
Vukasin Avatar answered Sep 22 '22 06:09

Vukasin


There is a PHP code formatter named PhpBeautifier. Here you can find a Sublime Text plugin for this program and you can also install it via package control.

like image 25
Philipp Michael Avatar answered Sep 19 '22 06:09

Philipp Michael