Automatic formatting in VIM for PHP

I want to be able to use the following code

  if ($ something)
 {
    do something
 }

and do it

  if ($ somthing) {
     do something
 }

through the entire file without going to each statement and correcting it. I am not a regular expression guru, so any help would be appreciated :)

+4
source share
2 answers

Use PEAR PHP_Beautifier to reformat your code.

+2
source

You can:

  • Find a line containing if , but not ending in { :

     /if [^{]*$ 
  • Attach this line to the following:

     J 

You can match this sequence with something:

 nmap <F2> /if[^{]*$<CR>J 

so that each press of F2 changes the next one if the instance ( 100 F2 will change 100 instances, etc.).

0
source

All Articles