在vscode中快捷键ctrl+shift+p
,然后输入setting
,会出现下图几个选项
当不同设置之间出现冲突时,听谁的:
Open Workspace Settings(JSON) > Open Settings(JSON) = Open User Settings > Open Default Settings(JSON)
Open Workspace Settings(JSON):
点击该选项,会在当前工程目录下新建一个.vscode目录,在.vscode目录下,会多出一个settings.json文件,默认为空。
在这个settings.json文件中,可以写一些设置选项,这些设置选项仅仅对当前工程目录下的文件起作用.
此文件用于配置VS Code的C/C++扩展,提供正确的IntelliSense(代码完成、提示等)。
官网链接:https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference
模板为:
{
"env": { //定义了一组环境变量,这些变量稍后在配置中可以引用
"myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],//表示默认的头文件搜索路径
"myCompilerPath": "/usr/local/bin/gcc-7" //定义了一个编译器的路径
},
"configurations": [
{
"name": "Mac", //mac,linux,win32/描述了这个配置的目的或使用的环境
"intelliSenseMode": "clang-x64",
"includePath": ["${myDefaultIncludePath}", "/another/path"],//包含头文件搜索路径的数组。它引用了前面定义的环境变量myDefaultIncludePath并添加了另一个路径/another/path
"macFrameworkPath": ["/System/Library/Frameworks"],
"defines": ["FOO", "BAR=100"],
"forcedInclude": ["${workspaceFolder}/include/config.h"],
"compilerPath": "/usr/bin/clang", //用于构建项目的编译器的完整路径
"cStandard": "c11",
"cppStandard": "c++17",
"compileCommands": "/path/to/compile_commands.json",//指向一个compile_commands.json文件的路径,它提供了关于如何编译工程中各个文件的信息
"browse": {
"path": ["${workspaceFolder}"],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
官网链接:https://code.visualstudio.com/docs/cpp/launch-json-reference
launch.json 文件用于在 Visual Studio Code 中配置调试器。要开始调试,您需要在program
字段中填写您计划调试的可执行文件的路径。This must be specified for both the launch and attach (if you plan to attach to a running instance at any point) configurations.
生成的文件包含两部分,第一部分配置launch调试,第二部分配置attach调试
点击DEBUG->创建lauch.json
Set or change the following options to control VS Code’s behavior during debugging:
例子
{
"name": "C++ Launch (Windows)",
"type": "cppvsdbg",
"request": "launch",
"program": "C:\\app1\\Debug\\app1.exe",
"symbolSearchPath": "C:\\Symbols;C:\\SymbolDir2",
"externalConsole": true,
"logging": {
"moduleLoad": false,
"trace": true
},
"visualizerFile": "${workspaceFolder}/my.natvis",
"showDisplayString": true
}
program (required)
指定调试器将启动或附加的可执行文件的完整路径。调试器需要该位置才能加载调试符号。
symbolSearchPath
告诉 Visual Studio Windows 调试器搜索symbol(.pdb) 文件的路径。用分号分隔多个路径。例如"C:\Symbols;C:\SymbolDir2"。
requireExactSource
additionalSOLibSearchPath
Tells GDB or LLDB what paths to search for .so files. Separate multiple paths with a semicolon. For example: "/Users/user/dir1;/Users/user/dir2"
.
externalConsole
Used only when launching the debuggee. For attach
, this parameter does not change the debuggee’s behavior.
avoidWindowsConsoleRedirection
logging
可选标记,用于确定哪些类型的信息应记录到调试控制台。
https://blog.csdn.net/weixin_40579705/article/details/133788557?spm=1001.2014.3001.5501
存在远程debug容器中的
官网链接:https://code.visualstudio.com/Docs/editor/tasks
此文件定义了在VS Code中执行的任务。这些任务可以是编译、构建、运行脚本等。
ctrl+shift+p->task->使用模板创建tasks.json文件->others 运行任何外部命令的先例
以下为自定义task
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run tests",
"type": "shell",
"command": "./scripts/test.sh",
"windows": {
"command": ".\\scripts\\test.cmd"
},
"group": "test",
"presentation": {
"reveal": "always",
"panel": "new"
}
}
]
}
label
用户界面中使用的任务标签
type
任务类型。对于自定义任务,可以是 shell 或进程。如果指定 shell,命令将被解释为 shell 命令(例如:bash、cmd 或 PowerShell)。如果指定 process,命令将被解释为一个要执行的进程。
command
要执行的实际命令。
group
Defines to which group the task belongs. In the example, it belongs to the test
group. Tasks that belong to the test group can be executed by running Run Test Task from the Command Palette.presentation
options
覆盖 cwd(当前工作目录)、env(环境变量)或 shell(默认 shell)的默认值。选项可按任务设置,也可全局或按平台设置。此处配置的环境变量只能在任务脚本或进程中引用,如果它们是 args、命令或其他任务属性的一部分,则不会被解析。
runOptions
Defines when and how a task is run
示例:使用g++编译c++程序
{
"version": "2.0.0",
"tasks": [
{
"label": "g++ build active file",
"type": "shell",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
官网链接:https://code.visualstudio.com/docs/getstarted/settings
可以根据自己的喜好通过各种配置来配置vscode。几乎vscode的编辑器,用户界面和功能行为的每个部分都有可以修改的地方
不同的设置范围:
https://blog.csdn.net/weixin_40579705/article/details/131492235?spm=1001.2014.3001.5501