本文主要介绍VScode如何进行美化以及插件的安装,以提高生产力,使得编译单一文件并不需要开启Visual Studio、IDEA、Pycharm等大型IDE(其实就是懒OTZ),并使用部分插件提高生产效率和文件代码辨识度如图标美化、自动修改代码格式、自动重构等。
笔者效果图:
美化插件
One Dark Pro
界面美化主题插件One Dark Pro
VScode文件-首选项-颜色主题-One Dark Pro
vscode-icons
不再是单调的样式,一眼就能分别文件夹类型(public/js/tools/source)、文件类型
文件图标主题美化插件vscode-icons
VScode文件-首选项-文件图标主题-vscode-icons
VScode编译C/C++/Python文件
写在最前面:请摒弃VC6.0单文件编译的概念,VScode类似于各大型IDE需要有一个工程的概念,工作区等同于工程地址,请确保所有的代码文件都保存在此文件目录下,否则配置无法作用
VScode编译C/C++代码
首先安装微软提供的C/C++插件C/C++ for Visual Studio Code
必须安装本插件后,才可以配置C/C++编译环境!
可以选择LLVM、MinGW32、MinGW64、Tdm-gcc等主流编译环境的其中一个。其中LLVM前端(词法、语法分析、语义分析、生成中间代码)使用的是clang,效率上优于后面三个所使用的gcc,但是windows平台安装极为繁琐,故我们选择Tdm-gcc。
Tdm-gcc下载地址:
1
| https://nchc.dl.sourceforge.net/project/tdm-gcc/TDM-GCC%20Installer/tdm64-gcc-5.1.0-2.exe
|
Tdm-gcc安装教程
- Create
- MinGW -64/TDM64
- 安装地址配置(之后要配PATH,一定要记住安装在哪,另外目录里不要出现中文!)
- 选择SourceForge Default即可
- 选择TDM-GCC Recommented,C/C++即可
- 安装完毕后,我的电脑右键属性-高级系统设置-高级-环境变量-系统变量PATH检查gcc地址是否已经写入Path
至此gcc安装完毕,开始配置VScode使用GCC编译
VScode代码配置
在工作区环境下点击左侧瓢虫符号,点击齿轮配置launch.json,并会同时生成工作区.vscodew文件夹
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| { "version": "0.2.0", "configurations": [ { "name": "C++ Launch (GDB)", "type": "cppdbg", "request": "launch", "targetArchitecture": "x64", "program": "${fileDirname}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "externalConsole": true, "internalConsoleOptions": "neverOpen", "MIMode": "gdb", "miDebuggerPath": "D:/Programming_environment_IDE/TDM-GCC-64/bin/gdb64.exe", "setupCommands": [ { "description": "Enable pretty-printing for GDB", "text": "-enable-pretty-printing", "ignoreFailures": false } ], "preLaunchTask": "Compile" }, { "name": "Python3.6", "type": "python", "request": "launch", "stopOnEntry": false, "pythonPath": "D:/Programming_environment_IDE/Python36/python", "program": "${file}", "cwd": "${workspaceFolder}", "env": {}, "envFile": "${workspaceFolder}/.env", } ] }
|
在.VScode文件夹创建c_cpp_properties.json,同理所有路径需要替换为对应的GCC安装路径,常见的报错找不到stdlib.h iostream等都是因为VScode找不到文件地址
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| { "configurations": [ { "name": "Win32", "intelliSenseMode": "clang-x64", "includePath": [ "${workspaceFolder}", "D:/Programming_environment_IDE/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0include/c++", "D:/Programming_environment_IDE/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0include/c++/x86_64-w64-mingw32", "D:/Programming_environment_IDE/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0include/c++/backward", "D:/Programming_environment_IDE/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0include", "D:/Programming_environment_IDE/TDM-GCC-64/include/include", "D:/Programming_environment_IDE/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0include-fixed" ], "defines": [ "_DEBUG", "UNICODE", "__GNUC__=7", "__cdecl=__attribute__((__cdecl__))" ], "browse": { "path": [ "${workspaceFolder}", "D:/Programming_environment_IDE/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0include/c++", "D:/Programming_environment_IDE/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0include/c++/x86_64-w64-mingw32", "D:/Programming_environment_IDE/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0include/c++/backward", "D:/Programming_environment_IDE/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0include", "D:/Programming_environment_IDE/TDM-GCC-64/include/include", "D:/Programming_environment_IDE/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0include-fixed" ] }, "limitSymbolsToIncludedHeaders": true, "databaseFilename": "", "compilerPath": "D:/Programming_environment_IDE/TDM-GCC-64/bin/gcc.exe", "cStandard": "c11", "cppStandard": "c++17" } ], "version": 4 }
|
接下来创建tasks.json,作用为自动生成编译命令,无需手动输入
C/C++-g++
1
| g++ -ggdb 'd:\Work Station\Visual Studio\200-1.cpp' --std=c++11 -o 'd:\Work Station\Visual Studio\200-1.exe'
|
Python-shell
1
| cd 'D:\Work Station'; ${env:PYTHONIOENCODING}='UTF-8'; ${env:PYTHONUNBUFFERED}='1'; & 'D:/Programming_environment_IDE/Python36/python' 'c:\Users\liwen\.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\ptvsd_launcher.py' '--default' '--client' '--host' 'localhost' '--port' '8440' 'd:\Work Station\PycharmProjects\test.py'
|
tasks.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| { "version": "2.0.0", "tasks": [ { "label": "python3.6", "type": "shell", "command": "D:/Programming_environment_IDE/Python36/python", "args": [ "${file}" ] }, { "label": "Compile", "command": "g++", "args": [ "-ggdb", "'${file}'", "--std=c++11", "-o", "'${fileDirname}\\${fileBasenameNoExtension}.exe'"
],
"type": "shell",
"group": { "kind": "build", "isDefault": true },
"presentation": { "echo": true, "reveal": "always", "focus": false, "panel": "shared" },
"problemMatcher": { "owner": "cpp", "fileLocation": [ "relative", "\\" ], "pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 } } } ] }
|
最后还需要创建settings.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| { "window.zoomLevel": 0, "editor.snippetSuggestions": "top", "editor.minimap.renderCharacters": false, "editor.formatOnPaste": true, "editor.formatOnType": true, "editor.wordWrap": "on",
"C_Cpp.clang_format_sortIncludes": true, "[cpp]": { "editor.quickSuggestions": true }, "[c]": { "editor.quickSuggestions": true }, "problems.decorations.enabled": true, "C_Cpp.intelliSenseEngineFallback": "Enabled", "files.associations": { "*.cfg": "ini", "*.fsh": "glsl", "stack": "cpp", "iostream": "cpp", "ostream": "cpp", "*.tcc": "cpp", "cctype": "cpp", "clocale": "cpp", "cmath": "cpp", "cstdint": "cpp", "cstdio": "cpp", "cstdlib": "cpp", "cwchar": "cpp", "cwctype": "cpp", "exception": "cpp", "initializer_list": "cpp", "iosfwd": "cpp", "istream": "cpp", "limits": "cpp", "new": "cpp", "stdexcept": "cpp", "streambuf": "cpp", "system_error": "cpp", "type_traits": "cpp", "typeinfo": "cpp", "utility": "cpp" }, "python.pythonPath": "D:\\Programming_environment_IDE\\Python36\\python.exe", }
|
进行调试
VScode中一样能通过断点分析程序的变量、堆栈等,在对应代码行左侧点击生成小红点即可
警告:路径中包含中文可能会导致无法打开文件!
https://github.com/Microsoft/vscode-cpptools/issues/602
Python调试:
C/C++调试:
最后更新时间: