Keil使用自定义菜单创建“格式化代码风格”快捷键

效果:

1、安装 indent 格式化软件,将其添加至系统环境变量(方便在git cmd里批量进行格式化);

    可参考:https://blog.csdn.net/ixiaochouyu/article/details/38032741

    具体参数怎么用建议使用indent安装目录下的doc文件,以下贴上我设置的K&R风格格式化参数

/* 使用doc推荐的进行修改,进行注释的是我不需要的参数
-nbad 在声明区段后不要加上空白行
-bap 在程序或加上空白行
//-bbo if多个条件进行缩进
-nbc 在声明区段中,即使出现逗号,仍旧不要换行。
-br if(或是else,for等等)与后面执行跛段的"{"同行,且"}"不自成一行。
-brs KR结构体缩进
-c33 Put comments to the right of code in column n.
-cd33 Put comments to the right of the declarations in column n.
-ncdb 注释符号不要自成一行。
-ce 将else置于"}"(if执行区段的结尾)之后
-ci4 叙述过长而换行时,指定换行后缩排的格数。
-cli4 使用case时,switch缩排的格数。
-cp33 将注释置于else与elseif叙述右侧定的栏位n。
-cs 在cast之后空一格
-d0 Set indentation of comments not to the right of code to n spaces.
-di1 Put variables in column n. 一行一个变量
-nfc1 Do not format comments in the first column as normal.
-nfca Do not format any comments.
//-hnl 
-i4 缩进格数4
-ip0 设置参数的缩排格数。
-l75 行的长度
//-lp 叙述过长而换行,且叙述中包含了括弧时,将括弧中的每行起始栏位内容垂直对其排列。
-npcs 在调用的函数名称之后,不要加上空格。
//-nprs Do not put a space after every '(' and before every ')'.
-npsl 程序类型与程序名称放在同一行。
-saf Put a space after each for.
-sai Put a space after each if.
-saw Put a space after each while.
//-nsc Do not put the * character at the left of comments.
//-nsob 不用处理多余的空白行。
-nss 若for或while区段仅有一行时,在分号前不加上空格。
*/

/* linux 批量格式化脚本 */
find ./module -type f -name "*.c" | xargs indent  -nbad -bap -nbc -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -cp33 -cs -d0 -di1 -nfc1 -nfca -i4 -ip0 -l200 -npcs -npsl -saf -sai -saw -nss -br -ts4

2、Keil --> Tools --> Customize Tools Menu

    ---> prompt for Arguments 打勾,会在运行前提示生成的命令。

    ---> Run Mini 就是最小化运行

    注意参数选项,主要需要提取“被格式化目标文件的全路径”  ---> (#E)

   具体Keil设置的参数项可参考:https://blog.csdn.net/mlm2k/article/details/18925197

3、 经过以上简单的教程,相信你会有更好的调教方法!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值