Sublime Forum

How to change auto indentation?

#1

Hi,
when I program in C or C++, I notice that switch/case are automatically indented in a weird way I don’t like. The default behaviour is as follows:

switch(a)
{
case 1:
    {
        break;
    }
case 2:
    {
        break;
    }
default:
    {
        break;
    }
}

However, I would prefer it as follows:

switch(a)
{
    case 1:
    {
        break;
    }
    case 2:
    {
        break;
    }
    default:
    {
        break;
    }
}

I wonder how I could change this. It is very annoying during typing, having to manually indent the case all the time. I know it should be possible to configure this behaviour by editing some language definition file, but I would prefer not to touch the files that are bundled with ST since they will be overwritten the next time I update. So is there another possibility how I could change this default indent behaviour?

0 Likes

#2

It can be achieved by commenting out indentation rules for case and default at

0 Likes

#3

Perfect! that was exactly what I was looking for.
I also found out how to override the Indentation Settings.tmPreferences for that built-in package. It works like a charm now :slight_smile:

0 Likes

#4

For anyone wanting to know how to override the default package behavior, there are many guides online.
However, the way that I do it:
Use the Sublime Package Manager (CTRL+Shift+P), Install Package, “PackageResourceViewer”.
After install, CTRL+Shift+P again; ‘Open Resource’ and navigate to C++/Indentation Rules.tmPreferences: Make your edits then save the file. The behavior in this saved file will override the default behavior of the package.

0 Likes

#5

A more safe option would probably be to use OverrideAudit as it might be too easy to override the whole packgage with PackageResourceViewer.

0 Likes