Formatting PHP Code within Vim
Quick way to fix PHP indentation in vim is to visually select the lines you want to work with using shift-v, and then press equals (=) to trigger auto-formatting.
As for other formatting issues you're probably looking at employing some regex search and replaces, such as :%s/^M/\r/g
(that's ctrl-V ctrl-m, not caret-M) to fix line endings
Enter normal mode in vim and then type
1GVG=