Skip to content

Setting Up Automatic Clang Formatting In VSCode

matt-bekkers edited this page Oct 28, 2023 · 7 revisions

Setting Up Automatic Clang Formatting

  1. Locate the .clang-format file on your machine by typing "where clang-format" into the command line and copy its path.
  2. Install the "Clang-Format" extension in VSCode by Xaver.
  3. Open the VSCode settings.json file by navigating to file -> preferences -> settings or with the shortcut Ctrl + , . Select the file icon in the top right corner.
  4. Copy and paste the following code into the settings.json file, filling in the required fields:
"clang-format.executable": "path to clang-format copied above",
    "clang-format.style": "path to .clang-format within the packager repo" ,
    "editor.codeActionsOnSave": {
        "source.fixAll": true

    },
    "editor.formatOnSave": true,
    "clang-format.language.c.enable": true,
    "[c]":{
        "editor.defaultFormatter": "xaver.clang-format",
        "editor.wordBasedSuggestions": false,
        "editor.suggest.insertMode": "replace",
        "editor.semanticHighlighting.enabled": true,

    }
  1. Save the settings.json file and finish.