Visual Studio Code Clang

Since the day that Microsoft released Visual Studio Code, I had installed it on Windows instead of notepad++. Because VS Code does not have a built-in code formatter or beautifier by default, I was eager to see a more powerful VS Code with extensions. Now there it is. We can find many useful extensions on Visual Studio Marketplace. Recently I was writing C/C++ code on Ubuntu and found the extension Clang-Format for beautifying C/C++ code. Let’s take a glimpse of how to make clang-format works with Visual Studio Code on Windows and Linux.

Getting Started with Clang-Format

To install an extension, we can press Ctrl+Shift+P and type in “install extension”. When all extensions listed, search for “format”, and you will see the Clang-Format: After installing the extension, you need to restart VSCode.

To format code, you can call Command Palette again with Ctrl+Shift+P, and then input “format”: The shortcut Ctrl+Shift+I is for Linux. If you want to use it on Windows, you need to use Alter+Shift+F.

Using Ninja alongside Visual Studio. We recommend that developers who want the fastest incremental builds use the Ninja build system. You can use the generated Visual Studio project files to edit Clang source code and generate a second build directory next to it for running the tests with these steps: Check out clang and LLVM as described above. To configure a Visual Studio project to use Clang, right-click on the project node in Solution Explorer and choose Properties. Typically, you should first choose All configurations at the top of the dialog. Then, under General Platform Toolset, choose LLVM (clang-cl) and then OK. C visual-studio-code clang-format. Improve this question. Follow edited Jan 29 '20 at 11:53. Asked Jan 21 '20 at 11:54. Goosebumps Goosebumps. 720 1 1 gold badge 10 10 silver badges 26 26 bronze badges. Add a comment 2 Answers Active Oldest Votes.

  1. Using Clang in Visual Studio Code In this tutorial, you configure Visual Studio Code on macOS to use the Clang/LLVM compiler and debugger. After configuring VS Code, you will compile and debug a simple C program in VS Code. This tutorial does not teach you about Clang or the C language.
  2. How to use VS Code to build and debug C and C programs under Windows 10 with Clang 8 from MSYS2. We present a debugging example.Install Clang on Windows 10.

If you do not have Clang-Format installed on your system, you will see the prompt:

How to Install Clang-Format on Windows

Visual studio code clang format

Visual Studio Code Clang

Download Clang for Windows (32-bit) or Clang for Windows (64-bit).

Install the package and add the path of %LLVM% bin to your system environment.

The shortcut Alter+Shift+F now works in Visual Studio Code for Windows.

How to Install Clang-Format on Ubuntu 14.04

There are two ways to install clang-format on Ubuntu 14.04: the stand-alone clang-format-3.4 or Clang for x86 _64 Ubuntu 14.04. The package size of stand-alone is much smaller than the full LLVM.

If you choose to install clang-format-3.4, the VS Code extension can’t work instantly. It will still prompt you that no clang-format found. Why? The installed clang-format tool is named clang-format-3.4:

To make it work, you just need to create a symlink:

Alternatively, if you download and extract the LLVM package, you will find clang-format under clang+llvm/bin:

Similarly, create a symbolic link for clang-format:

Now, you can format code with Ctrl+Shift+I in Visual Studio Code for Linux.


Visual Studio Code Clang C++


Steps to use Visual Studio code with clang-format

Visual Studio Code Clang_format_style

  1. Launch VS Code Quick Open (Ctrl+P), paste the following command, and type enter ext install clang-format
  2. Download the executable using ” npm install -g clang-format ” . You need this to get the exe path(vscode extension install does not clearly tell you where the exe path is..)
  3. Go to run and type %appdata% and browse to find clang-format.exe under npm/nodemodules
  4. Go to Visual studio code and type Ctrl+Shift+P and type “user settings”. Open the user settings.json file and search for clang-format. Then copy the elements you want code to overwrite into the adjacent json file and save it to the root of your workspace.
    This is how your settings.json file(specific to your workspace, not your global settings.json) will look.
    When VS Code executes then the workspace settings , should override your global settings.
  5. This is how your workspace settings file should look-
    “”: “Google”,
    “editor.formatOnSave”: true


  6. Thats it. Open a sample json file. Type your code and save it should automatically format the json file.