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. Linux 关闭及重启方式

    一.shutdown 命令 作用:关闭或重启系统 使用权限:超级管理员使用 常用选项 1. -r 关机后立即重启 2. -h关机后不重启 3. -f快速关机,重启时跳过fsck(file system ...

  2. sqlserver 时间 格式化

    0   或   100   (*)     默认值   mon   dd   yyyy   hh:miAM(或   PM)       1   101   美国   mm/dd/yyyy       ...

  3. Mac下载并编译Google安卓AOSP项目代码

    Mac下载并编译Google安卓AOSP项目代码 参考 https://source.android.com/source/index.html 这两天用Mac下载安卓AOSP源码,且把遇到的问题记下 ...

  4. sp_addlinkedserver的一些操作

    sp_addlinkedserver 创建一个链接的服务器,使其允许对分布式的.针对 OLE DB 数据源的异类查询进行访问.在使用 sp_addlinkedserver 创建链接的服务器之后,此服务 ...

  5. UITextView/UITextField检测并过滤Emoji表情符号

    UITextView/UITextField检测并过滤Emoji表情符号 本人在开发过程中遇到过这种情况,服务器端不支持Emoji表情,因此要求客户端在上传用户输入时,不能包含Emoji表情.在客户端 ...

  6. C# 多线程、结构体

    struct IpAndPort { public string Ip; public int Port; } private void Form1_Load(object sender, Event ...

  7. SGU 193.Chinese Girls' Amusement

    /* 实际上就是求一个k,满足k<=n/2,且gcd(n,k)=1 如果n为奇数,k为[n/2] 如果n为偶数,k=n/2-1-(n/2)%2 */ #include <iostream& ...

  8. grunt 合并压缩任务

    module.exports = function(grunt) { // LiveReload的默认端口号,你也可以改成你想要的端口号 var lrPort = 35729; // 使用connec ...

  9. JSP执行过程

    JSP执行流程: @1.客户端发出请求. @2.Web容器将JSP转译成Servlet源代码. @3.Web容器将产生的源代码进行编译. @4.Web容器加载编译后的代码并执行. @5.把执行结果响应 ...

  10. opencv数据结构总结

    OpenCV里面用到了很多图像相关的数据结构,熟练掌握它们是学习图像的基础. 1.IplImage IplImage IplImage IPL 图像头 typedef struct _IplImage ...