Sublime Forum

Random indentation behaviour

#1

I want very simple indentation behaviour and cannot get it. In fact, it applies indentation randomly.

When I press enter, I want my cursor to be at the indentation level of the previous line.

  • If the previous line is a comment, indent it to that level.
  • If the previous line is an open bracket/brace/parenthesis/angle bracket, indent it to that level.
  • If the previous line is 8 spaces, indent it to that level.
  • If the previous line is not indented, indent it to that level.

I think C++ syntax might be applying some logic that I don’t want, but can’t find how to fix it, let alone universally.

When I create a new file with no syntax, the indentation behaviour is correct.

Does anyone know how I can figure this out?

0 Likes

Shift+Enter --> Enter without indentation
#2

@kingkeith wrote up a large post that describes how the indentation system in Sublime works which can be found at the below linked post. Generally speaking the indent is a combination of your user preference settings for indent along with specific metadata that applies rules for indentation based on the surrounding text.

0 Likes

#3

Thank-you, @OdatNurd . That’s a great post. It is more than I was hoping for!

It explains all the inconsistent behaviour I see.

Specifically, I was getting:

{
} // this line was indented, then unindents properly
{
    } // this line does not unindent
    {
    } // and so on...

which you show is covered by https://github.com/SublimeTextIssues/Core/issues/1262

Then there’s the nuisance of trying to make an elevated comment:

    previousCodeSetsTheIndentLevel();
    
        // I want the next few lines to be indented to this level
    // <-- But it puts it here
    // Every time

This, you explain, is by design.

Still, it would be nice to get it working.

Once again, many thanks!
-David

0 Likes