Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Q: Can I configure VSCode to take a .clang-format file from my home directory?

I want to use the same clang-format file for all my project since I have multiple. But I don't want to have them in every workspace and i already have a clang-format file in my home directory, how can I make this work? Or is this impossible?

I have already seen this question: How can i configure clang format without .clang-format file in every workspace?

but my clang-format file is like 80 lines long and I just want to edit the stuff locally on my home without having to change it in vscode as well.

like image 614
Zwei Euro Avatar asked Oct 22 '19 17:10

Zwei Euro


People also ask

How do I run clang format locally?

You can install clang-format and git-clang-format via npm install -g clang-format . To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows.

Where is clang format stored?

clang-format is located in clang/tools/clang-format and can be used to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.


1 Answers

Maybe this will help.

The clang-format -style=file is somewhat misleading.

file is not the path to the file you want but rather tells clang-format to use the .clang-format file it can find within the project folders - going all the way up.

And as VSCode is the case, the C++ extension is using by default the clang-format in the VSCode extensions folder. Which should make the clang-format to go cd .. until it finds .clang-format in your workspace folder

like image 166
Shahar Hadas Avatar answered Oct 07 '22 19:10

Shahar Hadas