Visual Studio Code: exclude sections of a file from autoformat?
Asked Answered
S

1

7

I'm dealing with a bunch of legacy C code whose formatting is all over the place and I would like to clean it up as I work. However, there are some sections that I do not want touched (or I'd rather format manually (such as structures being used as bitfields with an explanation as to what each bit represents in comments). I'm working in an embedded environment, so understanding what each bit represents is important and keeping that nicely formatted is important, however, the C-lang formatter in VS Code wants to do its own thing with this kind of stuff.

How can I exclude sections of a file from autoformat?

Sexcentenary answered 20/3, 2018 at 14:47 Comment(0)
C
12

Are you using the clang-format extension clang-format ? If so, see disable formatting on a piece of code.

int formatted_code;
// clang-format off
    void    unformatted_code  ;
// clang-format on
void formatted_code_again;
Choreography answered 20/3, 2018 at 15:39 Comment(2)
I'm using the C/C++ extension (which gives me things like "go to definition," very important). It comes with a built-in C-lang formatter. Not sure if it'll work with the extension you pointed out. Any thoughts? I like that way of doing it. Just not sure if it'll play nice with Microsoft's extension. marketplace.visualstudio.com/items?itemName=ms-vscode.cpptoolsSexcentenary
Well, for me this should be definitely the accepted answer. This works perfectly! With the built in formatter with C/C++ extension.Naked

© 2022 - 2024 — McMap. All rights reserved.