0

I know that you can use the indent command to beautify c code. I want to do the same thing with php but the command is giving errors (it is intended for c only I believe) is there a standard way to formatt php code with a command? I would be open to either a unix command that comes with OS X or a VIM command.

2 Answers 2

5

If vim has been set up to recognize PHP, type =G at the top of your file and it will reindent your code to the end.

To expand on rkulla's comment, = is the indentation command, while G is the command to go to the end of the document and gg goes to the beginning. If you want to indent the next 5 lines beginning from your current line, you can type =5= or 5==.

Sign up to request clarification or add additional context in comments.

1 Comment

in other words, 'gg=G'. Or visually select just the block you want to indent and type '='. When pasting code that you want to indent properly, ':set paste' first, then paste.
3

If you are using VIM, erjiang's answer is the best method. For reference for yourself or anyone reading this who does not use VIM, there is a PEAR module for beautifying PHP called 'PHP Beautifier'.

http://beautifyphp.sourceforge.net

See command line usage in the documentation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.