首先说明一下,vscode 为我们提供了两种设置方式:
注:Workspace Settings 会覆盖 User Settings。
打开用户设置和项目设置的方法如下:
On Windows/Linux - File > Preferences > Settings
On macOS - Code > Preferences > Settings
或直接通过命令行面板(Ctrl+Shift+P)输入 open settings 进行调出。
vscode 中的 设置选项 都配置在一个 settings.json 文件中。
其中,用户设置(User Settings) 的路径为:
Windows %APPDATA%\Code\User\settings.json
macOS $HOME/Library/Application Support/Code/User/settings.json
Linux $HOME/.config/Code/User/settings.json
而 项目设置(Workspace Settings) 的路径为:根目录下的.vscode中
通用配置
{
// - onWindowChange: A dirty file is automatically saved when the window loses focus
// "files.autoSave": "onFocusChange",
// Controls the font size in pixels.
"editor.fontSize": 14,
// The number of spaces a tab is equal to. This setting is overridden based on the file contents when `editor.detectIndentation` is on.
"editor.tabSize": 4,
// Configure glob patterns for excluding files and folders. For example, the files explorer decides which files and folders to show or hide based on this setting. Read more about glob patterns [here](https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options).
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true
},
"editor.quickSuggestions": {
"other": true,
"comments": true,
"strings": true
},
}
配置:默认情况下,请确保各类语言的执行器配置在全局环境变量中。你也可以通过配置code-runner.executorMap设置执行器路径:
"code-runner.executorMap": {
"javascript": "node",
"php": "C:\\php\\php.exe",
"python": "python",
"perl": "perl",
"ruby": "C:\\Ruby23-x64\\bin\\ruby.exe",
"go": "go run",
"html": "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"",
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
},
"code-runner.runInTerminal": true
{
// 有关 tasks.json 格式的文档,请参见
// https://go.microsoft.com/fwlink/?LinkId=733558
"version": "2.0.0",
"tasks": [
{
"type": "shell", //任务执行的是shell命令
"label": "g++ build active file", // 任务的label,大小写区分的,等会在launch中调用这个名字
"command": "g++", // 命令是g++
"args": [
"-g",
"-std=c++11",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
// 所以以上部分,就是在shell中执行${file}为文件名
// g++ -g -std=c++11 filename.cpp -o fileDirname/fileBasename
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
//需要运行的是当前打开文件的目录中,名字和当前文件相同,
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
// 当前工作路径:当前文件所在的工作空间
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "g++ build active file" //launch 之前执行的任务 一定要跟tasks.json中的任务label大小写一致
}
]
}