In C++, I always align parameters on the open bracket (using clang-format). When I press the Enter key after that, the cursor always jumps to align with the indentation of the previous line by 4 spaces.
I have disabled all extensions to test for potential interference.
int main(int argc,
char **argv) {
_ <- cursor here
}
And what I want is, after pressing Enter, the cursor only indents 4 spaces.
int main(int argc,
char **argv) {
_ <- cursor should be here
}
I have tried and it meets the expected results in Sublime Text.
VS Code behavior: Gif
Sublime Text behavior: Gif
I tried to modify "auto-indent", but this setting cannot achieve my goal. Is there a way to change the behavior of VS Code to be like Sublime Text?
As of VS Code version 1.100 (May 2025) your desired behavior is not supported, without installing an extension.
There are 5 options for the editor.autoIndent
setting that controls the auto indentation, the feature you're discussing (source)
none
: The editor will not insert indentation automatically.keep
: The editor will keep the current line's indentation.brackets
: The editor will keep the current line's indentation and honor language defined brackets.advanced
: The editor will keep the current line's indentation, honor language defined brackets and invoke special onEnterRules defined by languages.full
: The editor will keep the current line's indentation, honor language defined brackets, invoke special onEnterRules defined by languages, and honor indentationRules defined by languages.In your example, without any extensions installed and selected language mode C++
, these collapse to 3 effective behaviors:
int main(int argc,
char **argv) {
_ <- `none`
_ <- `keep`
_ <- `brackets`/`advanced`/`full`
Your desired indentation by 4 spaces is not possible without extensions. I also haven't (yet) found an extension that would support your desired auto indentation.