Visual studio中AStyle Extension插件的安装和配置及使用
下载:
https://marketplace.visualstudio.com/items?itemName=Lukamicoder.AStyleExtension
安装:
下载完成后,安装过程很简单,略。
配置:(以vs2013为例,其他版本的配置过程基本一致)
打开菜单项Tools-> Options,在弹出的对话框中选择 ->AStyle Formatter -> General.
在你想要设置格式的语言的tab页中,单击Settings 按钮.
在弹出的对话框中,设置如下,(遵循google规范)
也可以参考http://astyle.sourceforge.net/astyle.html设置为其他规范.
使用:
选中需要规范格式的代码,选择菜单项Edit-> Advanced -> Format Document (AStyle).
也可以通过 Tools -> Options -> Environment -> Keyboard为上述操作设置快捷键.
批量格式化!
有时候你会有很多文件需要格式化成统一风格,难道一个个点击菜单?不!那样太累了。
在Windows中,我们可以用命令行来解决问题。这里用到一个超级命令 for
范例如下:
for /R %f in (*.cpp;*.c;*.h)do astyle --style=ansi "%f"
该命令在当前目录中寻找文件名匹配模式 *.cpp;*.c;*.h 的所有文件(不同模式可用英文逗号隔开),并且对每个文件%f执行操作:
astyle --style=ansi"%f"