Visual Studio Code Snippets don't work with K&R style braces

Roland 21 Reputation points
2021-04-16T13:39:08.133+00:00

I am running the latest version of Visual Studio 2019 (16.9.4). I have changed my C++ code to use K&R style braces by going to Tools > Options > Text Editor > C/C++ > Code Style > Formatting > New Lines and changing all the options to Keep on same line, but add a space before. The issue is that when I do this code snippets no longer work correctly, for example:

Normally when using Allman style braces the if code snippet would look like this:

if (true)
{

}

What I expected it to look like when using K&R style braces was this:

if (true) {

}

But what it actually looked like was this:

if (true)   {

}

This is very annoying as whenever I use a code snippet to complete an if statement, for loop or anything else I have to waste time removing the extra characters it inserts. Any help would be appreciated :)

Developer technologies C++
Developer technologies Visual Studio Other
{count} votes

Accepted answer
  1. Anna Xiu-MSFT 31,056 Reputation points Microsoft External Staff
    2021-04-19T08:55:40.303+00:00

    Hi @Roland ,

    Welcome to Microsoft Q&A!

    You can try the workaround posted by Viorel-1 to manually remove the space.

    Based on my testing, I can reproduce it, I suggest you report it to product team engineers by selecting “Help” menu > Send Feedback > Report a Problem.

    Sincerely,
    Anna

    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.