Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command-line program to indent PHP files

I'm looking for a indent application to fix all aspects of PHP code formatting - convert spaces, perform indentation in PHP and HTML code, leave HEREDOC alone, etc.

Please recommend a decent indenter for PHP.

like image 348
romaninsh Avatar asked Jul 05 '11 16:07

romaninsh


2 Answers

find . -name '*.php' -printf "echo -e \"G=gg\n:wq\n\" | vim %p\n" | sh
like image 61
Jim Avatar answered Oct 10 '22 07:10

Jim


I have found few things. First, the best way to mass-edit files is to use bash scripting and vim.

Second, vim indentation is not perfect and is not working always. So I had to rather do "=G" manually then review the source.

Finally, vim's command "retab" in collaboration with tab settings is great if only looking to change white-spaces into tabs.

I'd like to also point towards an awesome podcasts where I learned more about Vim:

  • http://vimcasts.org/episodes/show-invisibles/
  • http://vimcasts.org/episodes/tabs-and-spaces/
  • http://vimcasts.org/episodes/whitespace-preferences-and-filetypes/
  • http://vimcasts.org/episodes/tidying-whitespace/
like image 34
romaninsh Avatar answered Oct 10 '22 06:10

romaninsh