4

I tried to use shortcut to reindent and I have include this code for my Preferences → Key Binding - User

[
     { "keys": ["f3"], "command": "reindent" , "args": { "single_line": false } }
]

But when try to reindent the whole page it doesn't look god for the square brackets

For example when I type nested array like this

[
    nest => [
        child => [
            [
                grandchild => aaaa,
                grandchild2 => bbbb,
                grandchild3 => cccc
            ]
        ]
    ]
]

After that I want to reindent and it moves everything into this

[
nest => [
child => [
[
grandchild => aaaa,
grandchild2 => bbbb,
grandchild3 => cccc
]
]
]
]

How can I repair this?

0

1 Answer 1

2
+50

The issue is not caused by creating a shortcut key. I observed the same behavior by reindenting manually: Selection -> Select All, Edit -> Line, Reindent.

Sublime Text "reindents" according to the rules of the selected syntax.

With "Plain Text" selected, the code formats without indenting as you discovered.

With "Ruby" selected, the code reindents as you would expect.

4
  • While much closer, C++ doesn't give the expected result: [\n \t line \n \t ] Can we find a syntax that works better, so that others can be updated to match? Jul 3, 2015 at 0:34
  • 1
    Do you happen to know the language of the code sample? Also, selecting "Ruby" will indent as expected.
    – Steven
    Jul 3, 2015 at 0:45
  • The code in the question appears to be PHP (and valid). It's the language that brought me to this question, as well. Re:Ruby -- Thank you! Now it's just a matter of inspecting and updating the syntax files for other languages, I hope. That information alone is enough for me to award the bounty. Jul 3, 2015 at 0:48
  • While not Ruby code, the Ruby syntax does reindent this code sample correctly. Perhaps a complete PHP program would reindent better.
    – Steven
    Jul 3, 2015 at 0:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .