Visual studio中AStyle Extension插件的安装和配置及使用

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"

 

包含源代码,需要的可以自行下载。 把astyle.exe 复制到 C:\WINDOWS 目录里,省的指定路径 VC6++ 设置方法 菜单->工具->定制->工具菜单内容->新建菜单,参数如下 命令行:astyle.exe 变量: --style=k&r --brackets=break --indent=spaces --indent-cases --indent-preprocessor --pad-header --pad-oper --unpad-paren --keep-one-line-statements --keep-one-line-blocks --convert-tabs $(FileName)$(FileExt) 初始目录: $(FileDir) VC2008 外部工具里设置,还可以添加快捷键 命令:astyle.exe 参数: --style=k&r --brackets=break --indent=spaces --indent-cases --indent-preprocessor --pad-header --pad-oper --unpad-paren --keep-one-line-statements --keep-one-line-blocks --convert-tabs $(ItemFileName)$(ItemExt) 初始目录: $(ItemDir) CodeBlocks 设置差不多,很多绿色版的已经设置好了 AStyle_2.02_windows.zip bin 目录里有官方编译好的 Artistic Style 2.01 Maintained by: Jim Pattee Original Author: Tal Davidson Usage : astyle [options] Source1.cpp Source2.cpp [...] astyle [options] Beautified When indenting a specific file, the resulting indented file RETAINS the original file-name. The original pre-indented file is renamed, with a suffix of ".orig" added to the original filename. Wildcards (* and ?) may be used in the filename. A 'recursive' option can process directories recursively. By default, astyle is set up to indent C/C++/C#/Java files, with four spaces per indent, a maximal indentation of 40 spaces inside continuous statements, a minimum indentation of eight spaces inside conditional statements, and NO formatting options.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小帆别吃糖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值