CSDN又限制博客名字。。被迫改名。。以后该专栏改成Noob Notes
VScode 常见配置、插件推荐以及常见问题(一)
VScode 的常见配置
VScode的功能强大就在于他的插件很多很多很多,你可以根据需要进行安装,且界面美观,很友好,可玩性强。
对于常见的配置问题,这里只讲C/C++
Python的可以移步这里——Python学习日记(1)Python 环境搭建 与 IDE的配置(PyCharm与VScode)
其他的咱也不会
然后因为对于本文的重点在于Error Lens 不显示错误的原因和解决方案
其也涉及到C/C++的配置问题,所以就放到下面一起讲了
插件推荐以及常见问题
插件安装在这,直接搜就好
Chinese (Simplified) (简体中文)
汉化插件,基本必装,装完重启VScode就好了
Code Runner
程序运行插件,有一个就够了
推荐设置
往下滑,推荐勾选这两个,第一个是启用Code Runner,第二个是运行前保存
不然每次运行前都按一下保存挺麻烦的
Code Runner 运行的快捷键是 Ctrl + Alt +N
当然也可以自己设置
background-cover
背景图片的插件,背景的插件有很多,个人推荐这个
安装完重启VScode,右下角这个地方就可以换背景图片了
但是会显示VScode已损坏,可以用这个插件进行修复,虽然不修复也感觉没啥事,但是一直弹消息也是挺烦的
还有就是,有的时候背景会加载不出,重新设置背景就好了
vscode-icons
代码图标
indent-rainbow
让你的不同缩进带上不同颜色
具体效果就是这样
Bracket Pair Colorizer
配对的括号颜色相同
Error Lens
可以对代码进行报错,且直接显示在代码行,十分好用!!!
效果如下
其他语言一样可以
但是有一个问题,就是我之前写C++代码的时候, Error Lens 不会显示错误,找了很久才找到原因,原来是Error Lens 识别不了错误并显示(注意:Error Les只是 将 错误、警告和其他语言诊断的突出显示),只是突出显示,具体的错误识别还是要看原来的环境
安装完相应的编译环境,把配置文件搞好就行了
解决方案:
首先要确保安装了C/C++
然后
在你放代码的文件夹里加个文件夹,命名为 .vscode
在里面新建这三个配置文件
这三个配置文件代码如下:
直接复制就好了,然后就能正常显示错误了
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", // 配置类型,这里只能为cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录
"environment": [],
"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
"MIMode": "gdb",
"miDebuggerPath": "D:\\collage_3\\C_language\\Dev-Cpp\\MinGW64\\bin\\gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应
"preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
settings.json
{
"files.associations": {
"utility": "cpp",
"xtree": "cpp",
"vector": "cpp",
"algorithm": "cpp",
"queue": "cpp",
"stack": "cpp",
"cmath": "cpp",
"random": "cpp",
"numeric": "cpp",
"ostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"cfenv": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"cinttypes": "cpp",
"clocale": "cpp",
"compare": "cpp",
"complex": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"csetjmp": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"exception": "cpp",
"coroutine": "cpp",
"resumable": "cpp",
"format": "cpp",
"forward_list": "cpp",
"fstream": "cpp",
"functional": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ratio": "cpp",
"regex": "cpp",
"scoped_allocator": "cpp",
"set": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"valarray": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xutility": "cpp"
}
}
tasks.json
{
"version": "2.0.0",
"command": "g++",
"args": ["-g","${file}","-o","${fileBasenameNoExtension}.exe"], // 编译命令参数
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}