- 搜索扩展Astyle并安装
- 下载Astyle:https://sourceforge.net/projects/astyle/files/,解压缩后添加Astyle.exe的路径到系统环境变量,例如我在Path中增加一条D:\vscode\AStyle_3.1_windows\AStyle\bin
- 重启vscode使环境变量生效
- 可修改astyle的配置:例如我在用户设置中增加字段
"astyle.additional_languages": [
"c",
"cpp",
],
"astyle.cmd_options": [
"--style=kr",//Kernighan&Ritchie 风格格式和缩进
"--indent=spaces=4",//缩进4个空格
"--convert-tabs",
"--align-pointer=name",
"--align-reference=name",
"--keep-one-line-statements",
"--pad-header",
"--pad-oper",//操作符两端插入一个空格
],
- 对C/C++源文件使用alt+shift+f测试格式重排