Deepin VSCode 安装 Astyle

安装 Astyle

  1. 下载 Astyle:https://sourceforge.net/projects/astyle/files/
  2. 下载完成解压缩后,进入其中的 doc 目录,打开 install.html 文档,里面有各种安装 Astyle 的方式。此处我选择的是 Linux 环境下的 Cmake 安装方式。
  3. 在 Astyle 根目录输入以下命令:
mkdir  as-gcc-exe
cd  as-gcc-exe
cmake  ../
make
  1. 安装完成后还需将 Astyle 的可执行文件所在的目录加入 PATH,可执行文件就在上述的 as-gcc-exe 的文件夹下面,编辑 ~/.bashrc 将该路径加入 PATH,并且 source ~/.bashrc 即完整安装 Astyle 。

配置 VSCode

  1. 在 VSCode 里安装 astyle 插件。
  2. 编辑 settings.json 文件,此处我是 "Ctrl + ," 打开设置,然后输入 "astyle" 来打开的。
    在 settings.json 中加入
"astyle.additional_languages": [
        "c",
        "cpp",
    ],
    "astyle.cmd_options": [
        "--style=allman",
        "--indent=spaces=4",
        "--indent-preproc-block",
        "--pad-oper",
        "--pad-header",
        "--unpad-paren",
        "--suffix=none",
        "--align-pointer=name",
        "--lineend=linux",
        "--convert-tabs",
        "--verbose",
    ],

注意 json 文件的格式,此处的选项使用的是 RT-Thread 的代码格式化选项。

  1. 对当前 C/C++ 文件按 "Ctrl + Shift + I" 即可完成代码格式化,网上有说按 "Alt + Shift + F" 来执行代码格式化,但我这里不行。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。