VSCode/Cursor 配置Clang-Format

1、下载安装插件:Clang-Format

2、下载安装Clang-Format运行文件

LLVM-19.1.5-win64.exe
3、解压上述文件至自定义文件夹

如:E:\soft\LLVM

4、自定义文件夹中存放:clang-format文件,内容可自己生成也可以网上找

注意文件格式需要为:UTF-8

eg:
        D:\Project\.clang-format
5、配置clang-format插件设置:

vscode/cursor的配置:Settings中

        estensions
                ->Clang-Format configuration

                        ->Clang-format:Executable: 自定义文件夹下bin下clang-format.exe文件
                                eg:E:\soft\LLVM\bin\clang-format.exe

6、配置保存文件自动调整格式

vscode/cursor的配置:Settings中

        Text Editor

                ->Formatting

                        ->Format On Save 勾选

                        ->Format On Save Mode 确认为 file

 7、配置所有工程均使用配置在settings.json中增加以下内容

        Windows下

        C:\Users\登陆用户下\AppData\Roaming\Code\User\settings.json

        增加内容(注意路径写法):

"clang-format.style" : "file",

    "clang-format.assumeFilename": "自定义文件夹\\.clang-format",

    "clang-format.executable": "自定义文件夹\\LLVM\\bin\\clang-format.exe",

    "clang-format.fallbackStyle": "自定义语言形式",

    "editor.defaultFormatter": "xaver.clang-format"

eg:

    // clang-format 扩展的配置

    "clang-format.style" : "file",

    "clang-format.assumeFilename": "D:\\Project\\.clang-format",

    "clang-format.executable": "E:\\soft\\LLVM\\bin\\clang-format.exe",

    "clang-format.fallbackStyle": "Google",

    "editor.defaultFormatter": "xaver.clang-format"
8、重启软件

如果不行在cursor/vscode的Settings.json中也添加上:

    "editor.defaultFormatter": "xaver.clang-format"

    "clang-format.executable": "自定义文件夹LLVM\\bin\\clang-format.exe"

参考文件:

解决:VS通过ClangFormat进行格式设置时出现错误 error:Got empty plain scalar-CSDN博客vscode配置clang-format自动格式化代码-阿里云开发者社区windows 下 vs code 格式化代码(clang-format)_the 'clang-format' command is not available. pleas-CSDN博客

你可能感兴趣的:(vscode,ide,编辑器,c++)