question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Small but infuriating undesired auto-indentation in C++ source files

See original GitHub issue
  • VSCode Version: Code 1.15.1 (41abd21afdf7424c89319ee7cb0445cc6f376959, 2017-08-16T18:05:38.342Z)
  • OS Version: Windows_NT ia32 10.0.14393
  • Extensions:
Extension Author (truncated) Version
Bookmarks ale 0.16.0
githistory don 0.2.3
xml Dot 1.9.2
cpptools ms- 0.13.1

Steps to Reproduce:

Here’s a small snippet, where ^ is the cursor position (not an actual character in the file!)

{
    if(x)
        foo();
}^

If I press ENTER, the closing bracket and the cursor are auto-indented:

{
    if(x)
        foo();
    }
    ^

This is a small but extremely distracting issue in code bases which don’t use brackets for single sub-statements.

Btw, “editor.autoIndent” is set to false

Reproduces without extensions: Yes/No - Yes

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:27 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
DaanDeMeyercommented, Nov 13, 2018

Not sure if this is the right place to post this, but I’m also having an issue with indentation in C++ source files. I’m not using the VSCode C++ extension so I’m assuming this behaviour is coming from stock VSCode.

When writing a function definition, after writing the opening brace (vscode automatically inserts the closing brace) and pressing Enter, vscode indents the next line and closing brace way too far. I’ve not found a setting to disable this. Setting autoIndent to false does not change the behaviour.

Example:

Before:

void IQuicHttpStream::OnReadComplete(CompletionOnceCallback callback,
                                     int result) {<cursor-is-here>}

After pressing Enter:

void IQuicHttpStream::OnReadComplete(CompletionOnceCallback callback,
                                     int result) {
                                       <cursor-is-here>
                                     }

Desired:

void IQuicHttpStream::OnReadComplete(CompletionOnceCallback callback,
                                     int result) {
  <cursor-is-here>
}
0reactions
kkurkiewiczcommented, Nov 2, 2022

Please see also #164177.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Indenting C Programs
If you used a poor indentation style, you will probably have trouble following the logic of the code. And it's your own code!...
Read more >
How do I make Emacs auto-indent my C code? - Stack Overflow
I set the return key to globally act as a new-line-and-intent in my ~/.emacs file: (global-set-key "\C-m" 'newline-and-indent).
Read more >
Copy with proper indentation - Visual Studio Blog
You want to share some code you've written with a colleague, so you select it in the editor and hit Ctrl + C...
Read more >
SMIE - Auto-indentation with incomplete information - arXiv
that they invariably only handle correctly a small subset of the language's syntax, but their main problem is the code's complexity and ......
Read more >
Disable auto-indent of properties … | Apple Developer Forums
Problem is that it now auto-indent my Objective C class properties and ... way of doing things, and a lot of example code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found