我正在运行 x86_64 GNU/Linux 机器,并在 neovim 中使用 clang-format 来格式化我的 C 代码。此外,我使用自己的 .clang 格式配置文件,该文件主要基于 Mozilla 的样式。
我对配置文件所做的更改直接转换为我格式化的源文件 (.c) 文件,但由于某种原因,头文件 (.h) 不遵循我的 .clang-format 配置文件中指定的格式样式。 它说每次我尝试格式化头文件时,clang-format 都成功运行,但格式本身与 .clang-format 文件中指定的内容无关,我做错了什么?
当我格式化源文件时,请记住所有格式都按照 .config-format 中指定的完美。
编辑: 我正在使用这些参数运行 clang-format 可执行文件(我的 .config-format 的路径)
clang-format --style=文件:/home/myusername/.config/formatting/.clang-format
我不认为
style=file
是这样运作的。来自clang-format --help
:
--style=<string> - Coding style, currently supports:
LLVM, GNU, Google, Chromium, Microsoft, Mozilla, WebKit.
Use -style=file to load style configuration from
.clang-format file located in one of the parent
directories of the source file (or current
directory for stdin).
Use -style="{key: value, ...}" to set specific
parameters, e.g.:
-style="{BasedOnStyle: llvm, IndentWidth: 8}"
我相信
style=file
实际上是默认行为。它基本上搜索父目录,直到找到名为 .clang-format
的文件。基本上:
./.clang-format
../.clang-format
../../.clang-format
如果您将
.clang-format
移动到当前工作目录的父目录,它将起作用。