Forrest logo
tool overview
On this page you find all important commands for the CLI tool clang-format. If the command you are looking for is missing please ask our AI.

clang-format

Clang-format is a command-line tool that helps developers maintain consistent code style in C, C++, and other related languages. It is part of the Clang project, which is a collection of open-source programming language tools developed by LLVM.

Clang-format automatically formats code according to a set of predefined rules or a custom configuration file. It can handle various code formatting aspects such as indentation, line breaks, spacing, and alignment of statements and expressions. By enforcing a consistent code style, clang-format improves code readability and maintainability, making it easier for developers to collaborate on projects.

Some key features of clang-format include:

  1. Configurability: It offers a wide range of options to customize the code formatting style to match different coding guidelines, project requirements, or personal preferences.

  2. Integration: Clang-format can be easily integrated into existing development workflows as it supports many popular code editors (such as Vim, Emacs, Visual Studio Code) and build systems like CMake, Gradle, and Makefile.

  3. Experimental support for different languages: While primarily designed for C and C++, clang-format also has experimental support for other languages like Java, JavaScript, and Protocol Buffers (protobuf).

To use clang-format, you need to install LLVM and then execute the clang-format command with the desired arguments specifying the input files or directories. It can format files in-place or print the formatted code to standard output for further processing.

Overall, clang-format simplifies the process of maintaining consistent code style and automates the tedious task of manual code formatting.

List of commands for clang-format:

  • clang-format:tldr:0fbd4 clang-format: Format a file and print the result to `stdout`.
    $ clang-format ${filename}
    try on your machine
    explain this command
  • clang-format:tldr:c1061 clang-format: Format a file using the `.clang-format` file in one of the parent directories of the source file.
    $ clang-format --style=file ${filename}
    try on your machine
    explain this command
  • clang-format:tldr:c9e1a clang-format: Format a file in-place.
    $ clang-format -i ${filename}
    try on your machine
    explain this command
  • clang-format:tldr:d0b04 clang-format: Format a file using a predefined coding style.
    $ clang-format --style=${select} ${filename}
    try on your machine
    explain this command
  • clang-format:tldr:f5461 clang-format: Generate a custom `.clang-format` file.
    $ clang-format --style=${select} --dump-config > ${-clang-format}
    try on your machine
    explain this command
tool overview