VS Code的环境配置
1.基本插件的安装
Chinese (Simplified) Language Pack for Visual Studio Code:简体中文代码
code runner:与代码提交有关
Material Icon Theme:文件夹图标(可在设置中去选择)
community material theme:主题插件(可在设置中去选择)
2.字体选择
推荐使用JetBrainsMono字体 非常美观 安装完成后在设置可添加
3.编程语言生态库(内核环境)
IDE:intergrated development environment
集成开发环境 即我们常说的编译器 比如c/c++的visual studio, java的IDEA, python的pycharm
其本质就是应用了编程语言的内核(c/c++的mingw64 java的jdk python的python)
作为轻量级的文本编辑器,vs code聚合众多插件 实现原生内核的编程
4.环境变量的创建
mingw64:在系统变量path中创建 路径指定为mingw64中bin的路径
jdk:分两步 首先在系统变量创建JAVA_HOME 然后在系统变量path中创建 路径指定为jdk的安装路径
python:安装时注意勾选添加环境变量(该安装自动添加在用户变量的path中)
检查安装成功的方法:
1.cmd调用:指令依次为 gdb g++ java --version python --version简写:名称 -v
2.打开环境变量按照上述匹配的路径逐一查验
5.编程语言插件
文本编辑器为升级为编译器作铺垫的必备插件(凡是系统提示推荐搭配安装的插件必须安装)
C/C++:C/C++
java:Java Extension Pack(含以下六种扩展包)
Language Support for Java(TM) by Red Hatredhat
Debugger for Java
Java Test Runner
Maven for Java
Project Manager for Java
Visual Studio IntelliCode
python:python
系统提示安装以下 pylance
jupyter
6.编程语言与生态库进行联系
vs code运行的本质是通过powershell(系统命令窗口)通过调用执行器进行程序的执行
语言与生态库的绑定(C的mingw的bin文件夹,java的java home中的jdk文件夹,python的python.exe)
环境变量的本质就是为路径的快速获取提供便捷的通道。
1)绑定各种语言插件与生态库
方法一:手动添加路径(无需环境变量)
java:打开设置-扩展-java 找到home选项 添加路径jdk/java
python:打开设置-扩展-python 找到python path 添加路径python.exe
弊端:C++没有这种方法的实现方式,必须通过环境变量+相应执行文件去引导
方法二:运行第一个程序(需要环境变量 通过提示完成绑定)
C/C++:运行后生成的launch,tasks这两个执行文件必须在根目录.vscode文件夹下(避免麻烦,可移植)
有关C的配置是借助调试完成运行与调试的生态库绑定
java:运行后选择java home匹配
python:运行后选择解释器版本 (调用命令面板 >python select interpretor亦可)
2)利用code runner实现便捷配置
code runner将代码运行快捷化(即通常的ctrl+F5效果)
如果各类语言的执行器配置在全局环境变量,使用code runner就可以直接执行(默认实现匹配 不必选择绑定)
如果没有配置环境变量,也可以通过以下code-runner.executorMap设置执行器路径:
"code-runner.executorMap": {
"javascript": "node",//node安装的时候即添加环境配置
"php": "C:\\php\\php.exe",
"python": "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自动匹配环境变量
- 利用系统运行时检测并完成绑定
- C特殊利用调试文件达到运行的目的
7.开始第一个程序
c/python新建文件即可 java打开命令面板 >create java project
我不选择快捷键的原因:电脑不同软件热键易冲突 而且太多不易记
8.其它必备插件
1.透明化插件
windows opacity
2.md书写插件(使用自带的更好 不必安装)
markdown all in one markdown preview enhanced
3.html运行(浏览器)插件
browser preview
open in browser
4.截图插件
code snap
5.快速生成注释插件
koroFileHeader 快捷键:ctrl+alt+t/i
6.代码格式化
beautify
右键选择快速格式化即可 系统自带的格式化不普适与所有代码类型
7.leetcode插件
注意该插件依赖于node.js环境
Debug leetcode
Leetcode
Leetcode Debugger for C++
Leetcode Extension Pack
8.compareit插件
实现文件内容的对比区分
9.code spell checker插件
单词拼写检查
10.background-cover插件
可以实现自定义背景的效果
再安装以下插件(修改CSS会出现不受支持字样)可进行形式上的修复
Fix VSCode Checksums
命令面板输入Fix Checksums: Apply
11.会了吧插件
右侧栏按钮可以查询生词
Google Translate插件
安装地址:
https://marketplace.visualstudio.com/items?itemName=hancel.google-translate&utm_source=ld246.com
如果某些插件商店没有,可以通过网址访问安装
ctrl+alt+t实现翻译并替换
12.Auto Rename Tag插件
自动标签闭合 用于html代码书写
13.Easy Less插件
自动实现less文件编译为css文件
14.Live Server插件
实现html文件的实时预览作用
15.Draw.io Integration插件
可以构画流程图与思维导图,并且方便导出
16.debugger for chrome
html代码在谷歌浏览器中调试
9.终端输出的分析
默认使用的是cmd(内嵌) 可以在settings.json配置中(可在窗口的选项中去选择)选择cmd还是powershell
运行输出的结果分析
按照系统的运行配置输出显示在终端(如果C通过调试的方法进行配置按照调试输出分析)
注意使用clear清屏解决问题 注意使用上键再次输入
settings.json中下述配置可以清除一些windows信息
"terminal.integrated.automationShell.windows": "",
"terminal.integrated.shellArgs.windows": ["-NoLogo"],
相关的一个插件code runner (默认结果输出在输出端)
可通过插件配置决定(体现在settings.json)输出在终端(避免在输出端为只读的困扰)等一些配置.
调试输出的结果分析
需要在相应的launch.json配置中添加
"externalConsole":false,//避免使用单独的cmd命令窗口 采取内嵌的形式
"internalConsoleOptions": "neverOpen", //避免跳到调试控制台 直接在终端中显示调试结果
10.使用的简易说明
- 安装插件可在相应的扩展商店进行安装
- 文件->首选项->设置可完成相应的配置(插件与系统本身) 体现在settings.json的更改
- 键盘热键可通过管理->键盘快捷方式进行调整 会生成相应文件keyboards在系统配置同级目录下
- 可打开管理->命令面板(ctrl+shift+p)实现快速查找更改相应配置的功能
- 每一次调试都会生成lauch,task与调试相关的文件,可以对应移植,避免每次均修改
建议这样的文件均要实现上述终端配置的添加(在编程语言与生态库已经建立联系的前提下)
非常特殊的一点是:C建立联系的配置要借助调试文件进行辅助添加,并移植至代码根目录
11.配置习惯
1.没有debug调试习惯,所以上述launch,tasks中添加终端配置与我无瓜
2.安装code runner插件,C/java/python配置一键绑定,无非可能提示选择一个版本类型
这样一来,C配置借助调试文件launch,tasks与我无瓜
总而言之:能不用调试文件(launch,tasks)就不用 避免每次移植的繁琐
以上操作的前提条件是完成环境变量的预先设立,环境变量可以说为终端窗口的迅速调用提供条件。
12.环境变量
系统环境变量对所有用户均有效 用户环境变量仅针对当前用户
环境变量在任意窗口仅需输入名称即可以调用(但是如果在某一用户窗口调别的用户则不可以)
本次配置时 C,java,node,git均位于系统环境变量
python,vs code位于用户环境变量
13.调试分析
调试需要相关插件进行支持,而运行只需要系统检测或手动绑定到相关生态库(或者使用code runner自动绑定生态库) 可能每种语言还需要安装每种编程语言的语言辅助插件。
前面特殊的一点是C的运行可以借助调试文件去实现运行的效果。
vs code官方支持调试的插件有C/C++,dubugger for java,python,debugger for chrome.
调试一个代码文件一般同时生成调试文件(可根据个人习惯去移植即可 不必每次生成)
特别补充一点
html文件因为需要在浏览器中显示(不同与代码文件) 所以对于运行安装的是browser preview ,open in browser
对于调试安装的是debugger for chrome 一般这种调试不会生成配置文件。
VS code json
系统配置(settings.json)
本文是针对前文已安装插件后的精美配置源文件(配置的本质是json)
前文说明:
1.默认配置不体现在用户json文件里,系统自带
用户配置文件是对系统配置文件的补充与覆盖
2.配置文件的位置:C:\Users\username\AppData\Roaming\Code\User (通过命令行面板输入 open settings 进行调出)
插件的位置:C:\Users\username\ .vscode
3.新建.vscode中放置单独的settings.json文件对以此为根目录的代码文件起局部空间配置的作用
- User Settings(用户设置):全局设置,对任意一个运行的 VS Code 都会起作用。
- Workspace Settings(项目设置):只对当前项目的设置。会覆盖user settings
我的配置(含插件配置 带注释)
{
"editor.suggestSelection": "first", //设定所有的设置选项默认选择第一个选项
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", //该项代表所有人为的修改覆盖默认值
"workbench.colorTheme": "Community Material Theme Darker High Contrast", //设置背景主题
"editor.fontFamily": "JetBrains Mono", //设置字体
"editor.fontLigatures": true, //连体字
"editor.fontSize": 14, //设置字体大小
"editor.smoothScrolling": false, // 滚动平滑关闭
"terminal.integrated.fontFamily": "JetBrains Mono", //控制终端显示的字体
"workbench.sideBar.location": "right", //设置资源管理器在右侧
"editor.acceptSuggestionOnEnter": "off", //按回车时是换行,只有tab才会接受Intellisense,避免回车的智能感知
"window.title": "${dirty}${activeEditorLong}${separator}${rootName}${separator}${appName}", //设置文件显示时上端标题行
"files.trimTrailingWhitespace": true, // 保存时,删除每一行末尾的空格
"files.insertFinalNewline": true, // 保存后文件最末尾加一整行空行,参照Linux
"editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;:\'\",.<>/?·~!¥…()—【】、;:‘’“”,。《》? ", //可以ctrl+backspce删除至下列符号
"workbench.iconTheme": "material-icon-theme", //设置文件夹主题
"files.autoGuessEncoding": true, // 启用后,会在打开文件时尝试猜测字符集编码
"editor.snippetSuggestions": "inline", //代码片段与其它建议一起显示
"editor.dragAndDrop": true, // 选中文字后,可以拖动调整位置
"editor.cursorSmoothCaretAnimation": true, // 移动光标时变得平滑
"editor.suggest.snippetsPreventQuickSuggestions": true, //智能触发clangd的snippets的跳转点(进行函数的跳转)
"editor.minimap.enabled": true, //开启代码缩略图
"window.zoomLevel": 0, // 整体放大
"workbench.settings.useSplitJSON": false, //配置文件json的呈现方式(是否分列)
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
}, //配置有关文件夹的相关设置
"git.enabled": true,
"git.ignoreMissingGitWarning": true, //git上传的有关配置
"python.languageServer": "Pylance", //与python相关联的语言支持插件
"python.pythonPath": "D:\\vs code\\python\\python.exe", //配置python所指明的环境变量路径
"java.home": "D:\\vs code\\java", //配置java所指明的环境变量路径
"open-in-browser.default": "Microsoft Edge", //设置预览html代码所使用的浏览器
"browser-preview.startUrl": "https://www.cnblogs.com/wqcstudy", //设置默认打开html预览的网址(嵌入型)
"browser-preview.chromeExecutable": "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge", //控制预览html代码的相关浏览器(嵌入型)
"winopacity.opacity": 255,//设置透明度插件的相关应用
"codesnap.target": "window",//设置代码截图的windows配置
"fileheader.cursorMode": {
"description": "",
"param": "",
"return": ""
}, //设置函数头部说明
"fileheader.customMade": {
"author": "wqc",
"description": "",
"Date": "Do not edit"
}, //设置文件头部说明
"leetcode.endpoint": "leetcode-cn",
"leetcode.workspaceFolder": "C:\\Users\\86158\\Desktop\\code-cpp\\leetcode",
"leetcode.defaultLanguage": "cpp",
"leetcode.hint.configWebviewMarkdown": false, //有关leetcode相关插件的配置
"editor.tokenColorCustomizations": {
"comments": "#82e0aa", //注释颜色
"settings": {
"fontStyle": " ", //取消注释斜体 可能是与插件冲突 暂时未成功
}
},
"editor.wordWrapColumn": 130,
"editor.wordWrap": "wordWrapColumn", //控制换行时每行字数
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.formatOnPaste": true, //控制代码自动格式化
"emmet.triggerExpansionOnTab": true, //内置的emmet插件打开tab展开缩写设置
"workbench.startupEditor": "newUntitledFile",//再次打开编辑器另外打开一个窗口
"[javascript]": {
"editor.defaultFormatter": "HookyQR.beautify"//代码格式化选择使用插件beautify
},
"[html]": {
"editor.defaultFormatter": "HookyQR.beautify"
},
"files.autoSave": "afterDelay"//在退出一个文件后自动保存内容
"backgroundCover.imagePath": "https://api.dujin.org/bing/1920.php",//设置背景插件背景图片地址
"backgroundCover.opacity": 1,//设置背景插件背景图片清晰度
"googleTranslateExt.replaceText": true,//设置谷歌翻译插件 是否开启直接替换功能
"vscodeGoogleTranslate.preferredLanguage": "English",//谷歌翻译参考的语言
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",//设置终端打开的命令窗口
"code-runner.saveFileBeforeRun": true,//code runner在运行时保存文件
"code-runner.showExecutionMessage": false,//code runner在运行时不显示多余的信息
"code-runner.runInTerminal": true,//code runner在终端显示输出结果 而不显示在只读的输出端
"code-runner.clearPreviousOutput": true //code runner在终端清除以往的输出
}
我的配置(含插件配置 不带注释)
{
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"workbench.colorTheme": "Community Material Theme Darker High Contrast",
"editor.fontFamily": "JetBrains Mono",
"editor.fontLigatures": true,
"editor.fontSize": 14,
"editor.smoothScrolling": false,
"terminal.integrated.fontFamily": "JetBrains Mono",
"workbench.sideBar.location": "right",
"editor.acceptSuggestionOnEnter": "off",
"window.title": "${dirty}${activeEditorLong}${separator}${rootName}${separator}${appName}",
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;:\'\",.<>/?·~!¥…()—【】、;:‘’“”,。《》? ",
"workbench.iconTheme": "material-icon-theme",
"files.autoGuessEncoding": true,
"editor.snippetSuggestions": "inline",
"editor.dragAndDrop": true,
"editor.cursorSmoothCaretAnimation": true,
"editor.suggest.snippetsPreventQuickSuggestions": true,
"editor.minimap.enabled": true,
"window.zoomLevel": 0,
"workbench.settings.useSplitJSON": false,
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
},
"git.enabled": true,
"git.ignoreMissingGitWarning": true,
"python.languageServer": "Pylance",
"python.pythonPath": "D:\\vs code\\python\\python.exe",
"java.home": "D:\\vs code\\java",
"open-in-browser.default": "Microsoft Edge",
"browser-preview.startUrl": "https://www.cnblogs.com/wqcstudy",
"browser-preview.chromeExecutable": "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge",
"winopacity.opacity": 255,
"codesnap.target": "window",
"fileheader.cursorMode": {
"description": "",
"param": "",
"return": ""
},
"fileheader.customMade": {
"author": "wqc",
"description": "",
"Date": "Do not edit"
},
"leetcode.endpoint": "leetcode-cn",
"leetcode.workspaceFolder": "C:\\Users\\86158\\Desktop\\code-cpp\\leetcode",
"leetcode.defaultLanguage": "cpp",
"leetcode.hint.configWebviewMarkdown": false,
"editor.tokenColorCustomizations": {
"comments": "#82e0aa",
"settings": {
"fontStyle": " "
}
},
"editor.wordWrapColumn": 130,
"editor.wordWrap": "wordWrapColumn",
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.formatOnPaste": true,
"emmet.triggerExpansionOnTab": true,
"workbench.startupEditor": "newUntitledFile",
"[javascript]": {
"editor.defaultFormatter": "HookyQR.beautify"
},
"[html]": {
"editor.defaultFormatter": "HookyQR.beautify"
},
"files.autoSave": "afterDelay"
"backgroundCover.imagePath": "https://api.dujin.org/bing/1920.php",
"backgroundCover.opacity": 1,
"googleTranslateExt.replaceText": true,
"vscodeGoogleTranslate.preferredLanguage": "English",
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"code-runner.saveFileBeforeRun": true,
"code-runner.showExecutionMessage": false,
"code-runner.runInTerminal": true,
"code-runner.clearPreviousOutput": true
}
我的配置(不含插件配置 不带注释)
必备插件:Chinese simplilfy,code runner,字体配置,文件夹主题(icon),背景主题(Community Material Theme)
{
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"editor.fontFamily": "JetBrains Mono",
"editor.fontLigatures": true,
"editor.fontSize": 14,
"editor.smoothScrolling": false,
"terminal.integrated.fontFamily": "JetBrains Mono",
"workbench.sideBar.location": "right",
"editor.acceptSuggestionOnEnter": "off",
"window.title": "${dirty}${activeEditorLong}${separator}${rootName}${separator}${appName}",
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"editor.wordSeparators": "`~!@#$%^&*()-=+[{]}\\|;:\'\",.<>/?·~!¥…()—【】、;:‘’“”,。《》? ",
"workbench.colorTheme": "Community Material Theme Darker High Contrast",
"workbench.iconTheme": "material-icon-theme",
"files.autoGuessEncoding": true,
"editor.snippetSuggestions": "inline",
"editor.dragAndDrop": true,
"editor.cursorSmoothCaretAnimation": true,
"editor.suggest.snippetsPreventQuickSuggestions": true,
"editor.minimap.enabled": true,
"window.zoomLevel": 0,
"workbench.settings.useSplitJSON": false,
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
},
"git.enabled": true,
"git.ignoreMissingGitWarning": true,
"editor.tokenColorCustomizations": {
"comments": "#82e0aa",
"settings": {
"fontStyle": " ",
}
},
"editor.wordWrapColumn": 130,
"editor.wordWrap": "wordWrapColumn",
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.formatOnPaste": true,
"emmet.triggerExpansionOnTab": true,
"workbench.startupEditor": "newUntitledFile",
"files.autoSave": "afterDelay",
"code-runner.saveFileBeforeRun": true,
"code-runner.showExecutionMessage": false,
"code-runner.runInTerminal": true,
"code-runner.clearPreviousOutput": true
}
CPP的局部空间配置
{"files.defaultLanguage":"c++",
"C_Cpp.clang_format_sortIncludes": true,
"C_Cpp.autocomplete": "Default",
"C_Cpp.suggestSnippets": true,
"[c]": {
"files.encoding": "utf8"
},
"[c++]": {
"files.encoding": "utf8"
},
"files.associations": {
"iostream": "cpp",
"algorithm": "cpp",
"*.tcc": "cpp",
"random": "cpp",
"fstream": "cpp",
"istream": "cpp",
"ostream": "cpp",
"regex": "cpp",
"utility": "cpp",
"array": "cpp",
"atomic": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"cfenv": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"csetjmp": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cuchar": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ratio": "cpp",
"set": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"scoped_allocator": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"queue": "cpp"
},
"C_Cpp.errorSquiggles": "Enabled"
}
C的调试(debug)配置——用于C配置的执行文件
一旦运行调试会对应生成,且只管一级,注意每次移植,与上述的局部settings.json可管根目录不同,注意区别
launch.json(调试配置 调用tasks的编译输出)
// https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md
{
"version": "0.2.0",
"configurations": [{
"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", // 配置类型,cppdbg对应cpptools提供的调试功能;可以认为此处只能是cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"program": "${fileDirname}/${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,相当于在main上打断点
"cwd": "${workspaceFolder}", // 调试程序时的工作目录,此为工作区文件夹;改成${fileDirname}可变为文件所在目录
"environment": [], // 环境变量
"externalConsole": false, // 为true时使用单独的cmd窗口,与其它IDE一致;18年10月后设为false可调用VSC内置终端
"internalConsoleOptions": "neverOpen", // 如果不设为neverOpen,调试时会跳到“调试控制台”选项卡,你应该不需要对gdb手动输命令吧?
"MIMode": "gdb", // 指定连接的调试器,可以为gdb或lldb。但我没试过lldb
"miDebuggerPath": "gdb.exe", // 调试器路径,Windows下后缀不能省略,Linux下则不要
"setupCommands": [
{ // 模板自带,好像可以更好地显示STL容器的内容,具体作用自行Google
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "Compile" // 调试会话开始前执行的任务,一般为编译程序。与tasks.json的label相对应
}]
}
tasks.json(编译配置)
// https://code.visualstudio.com/docs/editor/tasks
{
"version": "2.0.0",
"tasks": [{
"label": "Compile", // 任务名称,与launch.json的preLaunchTask相对应
"command": "g++", // 要使用的编译器,C++用g++
"args": [
"${file}",
"-o", // 指定输出文件名,不加该参数则默认输出a.exe,Linux下默认a.out
"${fileDirname}/${fileBasenameNoExtension}.exe",
"-g", // 生成和调试有关的信息
"-Wall", // 开启额外警告
"-static-libgcc", // 静态链接libgcc,一般都会加上
"-fexec-charset=utf-8", // 生成的程序使用GBK编码,不加这一条会导致Win下输出中文乱码
// "-std=c11", // C++最新标准为c++17,或根据自己的需要进行修改
], // 编译的命令,其实相当于VSC帮你在终端中输了这些东西
"type": "process", // process是vsc把预定义变量和转义解析后直接全部传给command;shell相当于先打开shell再输入命令,所以args还会经过shell再解析一遍
"group": {
"kind": "build",
"isDefault": true // 不为true时ctrl shift B就要手动选择了
},
"presentation": {
"echo": true,
"reveal": "always", // 执行任务时是否跳转到终端面板,可以为always,silent,never。具体参见VSC的文档
"focus": false, // 设为true后可以使执行task时焦点聚集在终端,但对编译C/C++来说,设为true没有意义
"panel": "shared" // 不同的文件的编译信息共享一个终端面板
},
"problemMatcher":"$gcc" // 此选项可以捕捉编译时终端里的报错信息;但因为有Lint,再开这个可能有双重报错
}]
}