Hello!
I’m trying to work with clang-format and I struggle to specify my own clang-format configuration file.
I’m working on windows with VS code and I’m just trying to specify the configuration file I wrote…
How do I do it?
Thanks!
Hello!
I’m trying to work with clang-format and I struggle to specify my own clang-format configuration file.
I’m working on windows with VS code and I’m just trying to specify the configuration file I wrote…
How do I do it?
Thanks!
Hi,
You usually just put the file in the top most folder of your project and when the clang-format or clangd extension is active, the formatter should automatically find your .clang-format
file.
Afaict it always searches the folder tree upwards from the to-be-formatted file until it finds a config file (or not).
Cheers
Thank you for your answer!
I already figured it out, but is there a way to config it once and for all for all of my project?
I don’t realy wanna push this file to every one of my repos…
thanks again!
If your project doesn’t have .clang-format
file, clang-format
will try to find this configuration file in your home directory. So, maybe you could make use of this feature.(In fact, this assumes the code is located under the home folder. When clang-format searches upwards, it will finally find this file.)
Thanks again! can you give me the path to the home folder? Im working on Windows, was trying to put it in %APPDATA% but it didn’t work
It’s not %APPDATA%, it’s the directory named by your user name, a.k.a the parent directory of %APPDATA%.
Nope, still doesn’t work
Did you put your code under your home directory?
Hmm…nope, it’s under the C drive(c:\projects\my_project)
Then, you probably need to put this file under c:\
In that case you could just put it into the c:\projects folder, all projects in that folder will then eventually use that config file (remember it searches from the to-be-formatted file to the root).
It actually is good practice to commit the .clang-format file to the repo, though… Then all devices you use to work on the project or all other contributiors immediately use the right config file and you don’t get commits reformatting files by accident…