1.ubuntu安装astyle
sudo apt install astyle
2.vscode安装扩展 astyle
3.在setting.json配置风格
"astyle.executable": "/usr/bin/astyle",
"astyle.additional_languages": [
"c",
"cpp",
"*.h",
],
"astyle.cmd_options": [
"--recursive",
"--style=linux",
"--convert-tabs",
"--indent=spaces=4", // 每行4空格缩进
"--max-code-length=80", // 每行80个字符长度
"--attach-closing-while",
"--attach-return-type-decl",
"--indent-switches",
"--indent-continuation=4",
"--indent-preproc-block",
"--indent-preproc-define",
"--indent-preproc-cond",
"--indent-col1-comments",
"--pad-oper",
"--pad-comma",
"--pad-header",
"--unpad-paren",
"--align-pointer=name",
"--align-reference=name",
"--break-closing-braces", // 大括号后换行
"--add-braces",
],
4.使用 ctrl+shit+i执行格式化代码