Search code examples
cheader-filesneovimclang-format

clang-format is not formatting C header files (.h) according to its config file


I am running x86_64 GNU/Linux machine and using clang-format in neovim to format my C code. Additionally I am using my own .clang-format config file that is mostly based on style from Mozilla.

Changes I do to my config file directly translate to the source files (.c) files I format, but for some reason header files (.h) do not follow the formatting style specified in my .clang-format config file. It says the clang-format was ran successfully each time I try to format the header file but the formatting itself is nothing as specified in .clang-format file, what am I doing wrong?

Keep in mind everything formats perfectly as specified in .config-format when I format source files.

EDIT: I am running the clang-format executable with these arguments (path to my .config-format)

clang-format --style=file:/home/myusername/.config/formatting/.clang-format


Solution

  • When running clang-format from command line to format a file it is necessary to use the -i option.

    This indicates clang-format to do an inplace edit and, hence, to overwrite the file with the new format.

    Calling clang-format without the -i will format the file but not save it anywhere