Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 3 Reindent with proper array parenthesis in PHP

I Have a problem like that

but answer in link above don't helped me. I get used to reindent whole file while coding and I liked Sublime Text very much. But this bug makes me mad. So I need to reindent whole PHP files with shortcut and don't get wrong indenting.

This is how i need:

And this is how it does:

like image 378
GoldenTabby Avatar asked Mar 19 '14 14:03

GoldenTabby


People also ask

How do I fix indentations in Sublime Text?

That's quite simple in Sublime. Just Ctrl+Shift+P (or Command+Shift+P on MacOS) to open the tools pallet, type reindent , and pick Indentation: Reindent Lines . It should reindent all the file you are in, just remember to save before running the command, or it may not appear.

How do I align codes in Sublime Text 3?

Using Sublime Alignment ↩ Select the lines you wish to align. Press Ctrl+Alt+A (Windows & Linux) or Command+Ctrl+A (Mac OS X)

How do I indent multiple lines in Sublime Text?

You can use ctrl+ ] to indent a line (or highlighted block), and ctrl + [ to unindent.


1 Answers

As @BullfrogBlues mentions in a comment, the Sublime PHP Grammar plugin has a fix for this. I did not want that entire package, but fortunately it is very easy to extract out just the array indentation rule from there:

https://github.com/gerardroche/sublime-php-grammar/blob/master/Indentation%20Rules%20-%20Arrays.tmPreferences

Just save that file into the same directory where all your custom snippets etc. go (on Mac it's ~/Library/Application Support/Sublime Text 3/Packages/User, not sure about Windows/Linux) and voila!

like image 183
Jordan Lev Avatar answered Oct 19 '22 16:10

Jordan Lev