vs code中使用Astyle排版C/C++代码

  1. 搜索扩展Astyle并安装
  2. 下载Astyle:https://sourceforge.net/projects/astyle/files/,解压缩后添加Astyle.exe的路径到系统环境变量,例如我在Path中增加一条D:vscodeAStyle_3.1_windowsAStylein
  3. 重启vscode使环境变量生效
  4. 可修改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",//操作符两端插入一个空格
    ],
  1. 对C/C++源文件使用alt+shift+f测试格式重排
原文地址:https://www.cnblogs.com/sssaltyfish/p/10656768.html