clang-format-usage-in-vscode

install clang-format

1
pip3 install clang-format

Thus, it would be install in $HOME/.local/bin/clang-format

generate .clang-format file

1
clang-format --style=Google --dump-config > .clang-format

copy to your project

copy .clang-format to your project’s top directory

vscode settings

vscode install this extension: xaver.Clang-Format

open settings.json and add

1
2
3
4
5
6
7
{
"clang-format.executable": "${env.HOME}/.local/bin/clang-format",
"editor.formatOnSave": true,
"[cpp]": {
"editor.defaultFormatter": "xaver.clang-format"
}
}

unsatisfy with google style?

change .clang-format by yourself: options