2

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?

2
  • What you really want is probably clang-format.. Commented May 17 at 16:24
  • Yes, I am using clang-format. But I need to format it manually after I press the Enter key. I am looking for a way to do it automatically. Commented May 18 at 3:37

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer. Perhaps I need to go to GitHub to submit a feature request.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.