简体   繁体   中英

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 :)

使用PEAR的PHP_Beautifier重新格式化您的代码。

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 ( 100 F2 will change 100 instances and so on).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM