1

I installed the C/C++ Snippets extension in VS Code, and it creates a snippet like this:

for ( ) 
{
    // your code
}

but I want the open brace on the keyword line:

for ( ) {

I found this topic for C/C++ formation in VS Code: "Format Curly Braces on Same Line in C++ VS Code" but it didn't solve the problem (so, the snippet extension doesn't follow the C formatting "rules" in VS Code, I guess).

I can't find any setting in the VS Code settings JSON file for this extension.

Anyone have an idea?

(In the ideal world, the curly brace for functions would remain on the next line and only braces associated with keywords would be on the same line.)

Thank you,

-Vin

Gama11
  • 31,714
  • 9
  • 78
  • 100
VinDag
  • 45
  • 1
  • 7
  • Try this link https://medium.com/@nosuchstudio/formatting-curly-braces-on-the-same-line-in-c-in-vscode-c4937e1c215f – Ali Jibran Apr 09 '20 at 07:02
  • @AliJibran Sadly this did not do anything. I'm not using C# and not using Linux, so I just created the indicated JSON file and put it in the directory with the file I was editing. Restarted VS Code, closed and opened editing file. – VinDag Apr 09 '20 at 07:26
  • In vscode settings, try to search something like "CURLY" or "BRACE" it will show you the complete list. select C++ and change the settings as you desire. – Ali Jibran Apr 09 '20 at 07:54
  • try this : https://stackoverflow.com/a/50606364/4853427 – Ali Jibran Apr 09 '20 at 07:55
  • @AliJibran That also didn't help - no entry. It just found the one I already changes. The article you referenced was the one I mentioned in my original post. I've made that change but it does not affect the way the snippet creates the block. Thanks for trying - I may be out of luck. – VinDag Apr 09 '20 at 08:13

1 Answers1

1

I did some intense digging and found the name of the file that holds the snippits, then looked in all the "usual suspect" places and found it:

C:\Users\.vscode\extensions\hars.cppsnippets-0.0.14\snippets\

in this directory, there are two files: c.json, cpp.json

In each there are json entries for each snippit. I edited a couple in the c.json to test and they now format as I want. Thanks Ali! your suggestions got me thinking!

VinDag
  • 45
  • 1
  • 7