windows下sublime text 3使用clang format格式化C++代码

windows下sublime text 3使用clang format格式化C++代码,第1张

ref: 

 

Windows下clang-format的安装_wanlong1215的博客-CSDN博客_clang-format windows

https://gist.github.com/danielTobon43/51764026f95240bbd03991089f0380a8

llvm下载:

Download LLVM 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,使用该快捷键进行代码格式化

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 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/734333.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-27
下一篇 2022-04-27

发表评论

登录后才能评论

评论列表(0条)

保存