1. make your own format file at your project's root or file's folder. (The clang-format will automatically use the latest format file to format your code)

vim .clang-format

IndentWidth: 8

UseTab: Always

BreakBeforeBraces: Linux

AllowShortIfStatementsOnASingleLine: false

IndentCaseLabels: false

2. Then use the clang-format plug-in to automatically format your code.

Edit-->Clang-format-->Format File in Focus

Most likely, you'll have a .clang-format file at the root of your project.

So easy! so neat!

ClangFormat-Xcode

An Xcode plug-in to format your code using Clang's format tools, by @travisjeffery.

With clang-format you can use Clang to format your code to styles such as LLVM, Google, Chromium, Mozilla, WebKit, or your own configuration.

Installation:

Install via Alcatraz.

OR

Clone this repo, build and run ClangFormat, restart Xcode.

Usage:

Format on save

I.e., you press command-s and the file is formatted and wrote to disk.

In the menu, open Edit > Clang Format > Click Format on save (a checkmark appears in this menu item indicicating that the feature is active.)

Assign keyboard shortcuts

You can assign your own keyboard shortcuts like so:

  • Open the System Preferences > Keyboard > Shortcuts > App Shortcuts > Click +
  • Set the application to be Xcode
  • Set the menu title to an action title, e.g. "Format File in Focus"
  • Set your shortcut

In this example, we'll format the active file when control-i is pressed.

Using your own style configuration

By using Clang Format > File in the plug-in menu, Clang will look for the nearest .clang-format file from the input file. Most likely, you'll have a .clang-format file at the root of your project.

Here are the options for .clang-format and how they're configured.

If one of the built-in styles is close to what you want, you can bootstrap your own configuration with:

./bin/clang-format -style=llvm -dump-config > .clang-format

For example, this .clang-format is similar to the Linux Kernel style:

BasedOnStyle: LLVM
IndentWidth: 8
UseTab: Always
BreakBeforeBraces: Linux
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false

And this is similar to Visual Studio's style:

UseTab: Never
IndentWidth: 4
BreakBeforeBraces: Allman
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
ColumnLimit: 0

a great tool for automatically formating your code!的更多相关文章

  1. Cppcheck - A tool for static C/C++ code analysis

    cppcheck是一个个检测源码的工具,对编译工具的一个补充,mark Cppcheck - A tool for static C/C++ code analysis Syntax: cppchec ...

  2. 问题:Custom tool error: Failed to generate code for the service reference 'AppVot;结果:添加Service Reference, 无法为服务生成代码错误的解决办法

    添加Service Reference, 无法为服务生成代码错误的解决办法 我的解决方案是Silverlight+WCF的应用,Done Cretiria定义了需要在做完Service端的代码后首先运 ...

  3. Arch系统软件列表

    1. 安装统计 2. 安装列表 3. 安装说明 4. 作为依赖项的安装列表 5. 更正 mangaro使用减的方式安装系统.开箱即用的豪华版本,大部分人需要的都有了,同样包括个别用户不需要的,配置方面 ...

  4. Github上Python开发者应该关心的Repo

    carbaugh/lice lice : Generate license files for your projects 一个用来为你的项目生成许可证的工具.这下可方便了,不用手工的去修改了! co ...

  5. python模块 - 常用模块推荐

    http://blog.csdn.net/pipisorry/article/details/47185795 python常用模块 压缩字符 当谈起压缩时我们通常想到文件,比如ZIP结构.在Pyth ...

  6. Implementation with Java

    Implementation with Java From:http://jcsc.sourceforge.net In general, follow the Sun coding conventi ...

  7. Peer Code Reviews Made Easy with Eclipse Plug-In

    欢迎关注我的社交账号: 博客园地址: http://www.cnblogs.com/jiangxinnju/p/4781259.html GitHub地址: https://github.com/ji ...

  8. Scott Hanselman's 2014 Ultimate Developer and Power Users Tool List for Windows -摘自网络

    Everyone collects utilities, and most folks have a list of a few that they feel are indispensable.  ...

  9. Top 40 Static Code Analysis Tools

    https://www.softwaretestinghelp.com/tools/top-40-static-code-analysis-tools/ In this article, I have ...

随机推荐

  1. [转]Flex 布局教程:语法篇

    网页布局(layout)是CSS的一个重点应用. 布局的传统解决方案,基于盒状模型,依赖 display属性 + position属性 + float属性.它对于那些特殊布局非常不方便,比如,垂直居中 ...

  2. jsp中Java代码中怎么获取jsp页面元素

    举例,页面元素<td><input   value="${sl }" type="text" id="sl" name=& ...

  3. 自己写的自动生成动态边框的jquery小插件

    思路就是在元素四周添加<ul>列表,然后周期性地改变它的颜色,实现动态的效果,不支持ie7.ie8 预览链接http://gorey.sinaapp.com/myBorder/border ...

  4. Axure RP 8.0正式版下载地址 安装和汉化说明

    1.Axure RP和中文包包下载地址 官网地址:http://www.axure.com.cn/3510/ 2.下载完成后安装 3.破解 axure8.0注册码激活码:(亲测可用)用户名:aaa注册 ...

  5. vim备注

    ① 用户path生效 在~/.bashrc中修改path,在~/.profile中source bashrc ② secureCRT着色方案 底色RGB:43 43 43 前景色RGB:221 221 ...

  6. 十、C# 异常处理

    1.多异常类型 2.捕捉异常 3.常规catch块 4.异常处理的指导原则 5.定义自定义异常   1.多异常类型 代码要引发任何异常,只需为要引发的异常实例实例附加关键字throw作为前缀.具体选择 ...

  7. 解决js浮点数计算bug

    1.加 function add(a, b) { var c, d, e; try { c = a.toString().split(".")[1].length; } catch ...

  8. java_设计模式_单例模式_Singleton Pattern(2016-08-04)

    概念: 单例模式确保某个类只有一个实例,而且自行实例化并向整个系统提供这个实例. 适用场景: 在计算机系统中,线程池.缓存.日志对象.对话框.打印机.显卡的驱动程序对象常被设计成单例.这些应用都或多或 ...

  9. 【ZOJ2112】【整体二分+树状数组】带修改区间第k大

    The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with t ...

  10. 利用js获取时间并输出值

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...