Skip to content
| Marketplace
Sign in
Visual Studio Code>Formatters>Clang-Format Indent 4New to Visual Studio Code? Get it now.

Clang-Format Indent 4

Demiao Chen

demiao.cc
|
241 installs
| (3) | Free
Use Clang Format Indent 4 in Visual Studio Code
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Clang-Format Indent 4 for VS Code

License: MIT Marketplace

Code Formatter

Use clang-format to format your C/C++/Java/JavaScript/Objective-C/Objective-C++/Protobuf with indentations of 4 spaces like the following:

if (int i = 0; i < n; ++i) {
    while (true) {
        foo();
    }
} else {
    baz();
}

Acknowledgement

The extension is forked from Xaver Hellauer's Repo and modified to use clang-format with indent 4. More usage details can be found in the original repo.

Usage

Install clang-format use one of the following methods:

npm install -g clang-format       # NPM
sudo apt install clang-format     # Ubuntu Linux
winget install -e --id LLVM.LLVM  # Windows

Obtain the absolute path to clang-format:

which clang-format

Add the following to your vscode settings.json file (open with Ctrl/CMD+Shift+P and select Preferences: Open User Settings (JSON)):

{
  "clang-format.executable": "/absolute/path/to/clang-format",
}

To automatically format a file on save, add the following to your vscode settings.json file (example for C++):

{
  "editor.formatOnSave": true,
  "[cpp]": {
    "editor.defaultFormatter": "demiaochen.clang-format-indent-4",
  }
}

If you want to use a specific clang-format config file, add the following to your vscode settings.json file, and create a .clang-format file in the root of your project:

{
  "clang-format.style": "file",
}

Clang-Format

Clang-Format is a tool to format C/C++/Java/JavaScript/Objective-C/Objective-C++/Protobuf code. It can be configured with a config file named .clang-format within the working folder or a parent folder. Configuration see: http://clang.llvm.org/docs/ClangFormatStyleOptions.html

Source code

Available on github: https://github.com/demiaochen/vscode-clang-format-indent-4

  • Contact us
  • Jobs
  • Privacy
  • Terms of use
  • Trademarks
© 2023 Microsoft