简易 VS Code 配置

发布时间 2023-04-02 20:41:41作者: kymru

材料:

  • VS Code 本体

  • 编译器:mingw64 / TDM-GCC 64 等

步骤:

  • 下载 mingw64,解压至无中文的任意路径

    打开:此电脑 - 属性 - 高级系统设置 - 环境变量

    选择用户变量 - Path,单击编辑,双击空白区域,输入 mingw64 中 bin 目录的完整路径,全部确定

    *重启电脑

    使用 gcc --version 检验是否成功

  • 安装 VS Code 本体、

    选择插件,安装 C/C++ChineseCode RunnerTokyo Nightvscode-iconsMarkdown Preview EnhancedLaTeX WorkshopBracket Pair Colorization Toggler

    *安装 Competitive Programming Helper (cph)

    *新建用于存放所有代码的文件夹,作为工作区打开

    在目录中新建 .vscode 文件夹

    在其中新建 settings.jsontasks.json 以及 c_cpp_properties.json,复制以下内容。

    settings.json

    {
    	"[cpp]" : { "editor.wordBasedSuggestions": true },
    	"[c]" : { "editor.wordBasedSuggestions": true },
    	"C_Cpp.autocomplete": "disabled",
    	"C_Cpp.suggestSnippets": false,
    	"C_Cpp.errorSquiggles": "disabled",
    	"code-runner.executorMap": { 
    		"cpp": "cd $dir && g++ \"$fileName\" -std=c++14 -O2 -o \"$fileNameWithoutExt\" && \"$dir$fileNameWithoutExt\"",
    	},
    	"terminal.integrated.defaultProfile.windows": "Command Prompt",
    	"editor.insertSpaces": false,
    	"explorer.confirmDelete": false,
    	"editor.fontFamily": "Fira Code Medium, Jetbrains Mono, Cascadia Mono, Microsoft Yahei UI",
    	"editor.fontLigatures": true,
    	"cph.general.defaultLanguage": "cpp",
    	"cph.general.defaultLanguageTemplateFileLocation": "D:/Code/template/template.cpp",
    	"cph.language.cpp.Args": "-std=c++14 -Ofast",
    	"files.autoSave": "off",
    	"workbench.iconTheme": "vscode-icons",
    	"markdown-preview-enhanced.previewTheme": "vue.css",
    	"markdown-preview-enhanced.breakOnSingleNewLine": true,
    	"extensions.autoCheckUpdates": false,
    	"markdown-preview-enhanced.latexEngine": "xelatex",
    	"code-runner.runInTerminal": true,
    	"background.enabled": true,
    	"latex-workshop.latex.autoClean.run": "onBuilt",
    	"latex-workshop.latex.autoBuild.run": "never",
    	"latex-workshop.latex.recipe.default": "lastUsed",
    	"editor.useTabStops": false,
    	"extensions.ignoreRecommendations": true,
    	"[markdown]":{
    		"editor.unicodeHighlight.ambiguousCharacters": false,
    		"editor.unicodeHighlight.invisibleCharacters": false,
    		"editor.wordWrap": "on",
    		"editor.quickSuggestions": {
    			"other": "on",
    			"comments": "on",
    			"strings": "on"
    		}
    	},
    	"cph.general.timeOut": 3000,
    	"cph.general.ignoreSTDERROR": true,
    	"workbench.colorTheme": "Tokyo Night Storm",
    	"cph.general.autoShowJudge": false,
    	"extensions.autoUpdate": false,
    	"editor.minimap.enabled": false,
    	"editor.fontSize": 16,
    }
    

    tasks.json

    {
    	"tasks": [
    		{
    			"type": "cppbuild",
    			"label": "C/C++: g++.exe 生成活动文件",
    			"command": "D:\\mingw64\\bin\\g++.exe",
    			"args": [
    				// "-fdiagnostics-color=always",
    				"-g",
    				"${file}",
    				"-o",
    				"${fileDirname}\\${fileBasenameNoExtension}.exe",
    				"-std=c++14",
    				"-O2"
    			],
    			"options": {
    				"cwd": "${fileDirname}"
    			},
    			"problemMatcher": [
    				"$gcc"
    			],
    			"group": {
    				"kind": "build",
    				"isDefault": true
    			},
    			"detail": "调试器生成的任务。"
    		},
    		{
    			"type": "cppbuild",
    			"label": "C/C++: cpp.exe 生成活动文件",
    			"command": "D:\\mingw64\\bin\\cpp.exe",
    			"args": [
    				// "-fdiagnostics-color=always",
    				"-g",
    				"${file}",
    				"-o",
    				"${fileDirname}\\${fileBasenameNoExtension}.exe",
    				"-std=c++14",
    				"-O2"
    			],
    			"options": {
    				"cwd": "${fileDirname}"
    			},
    			"problemMatcher": [
    				"$gcc"
    			],
    			"group": "build",
    			"detail": "调试器生成的任务。"
    		}
    	],
    	"version": "2.0.0"
    }
    

    c_cpp_properties.json

    {
    	"configurations": [
    		{
    			"name": "Win32",
    			"includePath": [
    				"${workspaceFolder}/**"
    			],
    			"defines": [
    				"_DEBUG",
    				"UNICODE",
    				"_UNICODE"
    			],
    			"compilerPath": "D:/mingw64/bin/g++.exe",
    			"intelliSenseMode": "gcc-x64"
    		}
    	],
    	"version": 4
    }
    

    打开文件 - 首选项 - 设置

    屏蔽以 .exe 为后缀名的所有文件

    *更改 Run Code 快捷键

    *禁用自动补全和错误波形曲线

成功搭建类考场环境,完全拟真可以编译命令加入 -static