windows下sublime text 3使用clang format格式化C++代码
ref:Windows下clang-format的安装_wanlong1215的博客-CSDN博客_clang-format windowshttps://gist.github.com/danielTobon43/51764026f95240bbd03991089f0380a8llvm下载:Download LLVM releases安装后在sublime text package contro
update:
我发现windows系统直接在sublime text 3使用clang format插件有很大的bug,效果跟直接运行clang-format命令行结果不一样,经常不格式化或者部分格式化,可以考虑通过插件机制直接运行命令行对文件进行格式化:
sublime text自定义clang format插件格式化C++代码_Luchang-Li的博客-CSDN博客
ref:
Windows下clang-format的安装_wanlong1215的博客-CSDN博客_clang-format windows
https://gist.github.com/danielTobon43/51764026f95240bbd03991089f0380a8
llvm下载:
https://github.com/llvm/llvm-project/releases
安装后
在sublime text package control里面安装clang format插件
然后设置该插件:
Setting up clang-format
- Go to
Preferences->Package Control: Install Package
- Install
Clang Format
- Go to
Preferences->Package Settings->Clang Format->Setting-User
, set as following:
{
"binary": "C:/Program Files/LLVM/bin/clang-format.exe",
"format_on_save": true,
"style": "Custom",
}
- Go to
Preferences->Package Settings->Clang Format->Custom Style-User
, add:
{
"Language": "Cpp",
"TabWidth": 4,
"AlignTrailingComments": "true",
"UseTab": "Never",
}
可以把default的拷过来改。
- Save and restart sublime text
- Go to any script page, save it and see the difference
最后设置该插件的快捷键key bindings,使用该快捷键进行代码格式化(例如复制默认key bindings然后修改为ctrl+alt+r)
linux下代码格式化和保存配置文件
apt-get install clang-format-7 (其他系统版本可能apt-get install clang-format)
clang-format-7 -i xxx.cpp -style=Google
保存配置文件:
clang-format -style=Google -dump-config > .clang-format
配置文件修改
tab size
SortIncludes: false
加载配置文件进行格式化(自动从当前向上层目录寻找.clang-format配置文件):
clang-format-7 -style=file -i xxx.cpp
clang 14.0.0-RC1 or later now supports -style=file:<format_file_path>
after this change "Add option to explicitly specify a config file" entered the main branch. It's documented here.
.\LLVM14.0.0RC1\bin\clang-format.exe test.cpp -style=file:my_clang_format.txt
c++ - How do I specify a clang-format file? - Stack Overflow
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)