vscode配置AStyle格式化代码

伙伴们按照步骤来就可以成功,如果我写的不清楚,麻烦评论或者私信我。

一、打开vscode插件下载astyle

vscode配置AStyle格式化代码_第1张图片

二、下载AStyle并配置环境

1、官网下载http://astyle.sourceforge.net/下载最新版AStyle,解压到本地文件夹。

点击之后等待下载跳转。
vscode配置AStyle格式化代码_第2张图片

2、将解压的AStyle文件夹中bin文件夹路径添加到Windows的环境变量-系统变量-PATH。

(右键单击计算机,选择属性,搜索高级系统系统设置->高级,按步骤添加保存)

3、重启Windows,可以使环境变量更改起效。

三、ctrl+shift+p打开首选项设置,重启vscode生效。

vscode配置AStyle格式化代码_第3张图片
加入以下格式化配置,

    "astyle.additional_languages": [
        "c",
        "cpp",
    ],
    "astyle.cmd_options": [
        "--style=ansi",//ansi,bsd,kr...,Brace Style Options
        "--convert-tabs",//-c, Convert tabs to the appropriate number of spaces.
        "--indent=spaces=4",//-s4, Indent using 4 spaces per indent.
        "--indent-switches",//-S, Indent 'switch' blocks, so that the inner 'case XXX:' headers are indented in relation to the switch block.
        "--indent-namespaces",//-N, Indent the contents of namespace blocks.
        "--indent-labels",//-L, Indent labels so that they appear one indent less than the current indentation level, rather than being flushed completely to the left (which is the default).
        "--indent-continuation=4",//-xt4, Indent continuation lines an additional 4 indents.
        "--min-conditional-indent=0",//-m0, no minimal indent.
        "--max-continuation-indent=40",//-M40, Indent a maximal 40 spaces in a continuation line, relative to the previous line.
        "--break-blocks" //-f, Insert empty lines around unrelated blocks, labels, classes, ...
    ],

四、右键格式化代码

vscode配置AStyle格式化代码_第4张图片

你可能感兴趣的:(拓展技能,vscode,代码规范)