Stephan Grobler
Stephan Grobler

Reputation: 469

Auto formatting in VIM for PHP

I want to be able to take the following code

if ($something)
{
   do something
}

and make it

if ($somthing) {
    do something
}

through out a whole file without really going to each statement and correcting it. I am not a regex guru so any help would be appreciated :)

Upvotes: 4

Views: 1480

Answers (2)

Eelvex
Eelvex

Reputation: 9133

You can:

  1. Search for a line that contains if but doesn't end in {:

    /if [^{]*$
    
  2. Join this line with the next one:

    J
    

You can map this sequence to something:

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

so that every F2 press will change the next if instance (100F2 will change 100 instances and so on).

Upvotes: 0

cweiske
cweiske

Reputation: 31078

Use PEAR's PHP_Beautifier to reformat your code.

Upvotes: 2

Related Questions