vscode 配置
_Chthohepta_ · · 个人记录
基础设置
打开设置(Ctrl + ,),搜索并修改以下几项:
- 自动保存:搜索
Auto Save,选择afterDelay,避免因忘记保存导致代码丢失。 - Ctrl+滚轮缩放:搜索
Ctrl,勾选Editor: Mouse Wheel Zoom,像 Dev-C++ 一样用Ctrl + 滚轮调整字号。 - Tab 缩进:若习惯用 Tab,需搜索
Detect Indentation和Insert Spaces,全部取消勾选,否则 Tab 会被自动转为空格。 - 界面语言:NOI Linux 的 VS Code 默认为英文。可通过命令面板(
Ctrl+Shift+P)输入Configure Display Language,选择zh-cn并重启,但考场可能无法下载语言包,建议提前适应英文界面。
编译与运行配置
方式一:手动终端编译
打开内置终端(Ctrl + `),使用以下命令编译运行:
g++ 文件名.cpp -o 文件名 -std=c++14 -O2 -Wall
./文件名
方式二:配置 tasks.json 实现一键编译
如需在 VS Code 内按快捷键编译,可创建 .vscode/tasks.json 文件。
{
"version": "2.0.0",
"tasks": [
{
"label": "编译 C++(评测版)",
"type": "shell",
"command": "/usr/bin/g++",
"args": [
"-std=c++14",
"-O2",
"-Wall",
"-Wextra",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "silent",
"panel": "shared",
"clear": true
}
},
{
"label": "编译 C++(调试版)",
"type": "shell",
"command": "/usr/bin/g++",
"args": [
"-std=c++14",
"-O0",
"-g",
"-Wall",
"-Wextra",
"-fsanitize=address,undefined",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": false
},
"presentation": {
"reveal": "silent",
"panel": "shared",
"clear": true
}
},
{
"label": "运行 C++",
"type": "shell",
"command": "${fileDirname}/${fileBasenameNoExtension}",
"options": {
"cwd": "${fileDirname}"
},
"dependsOn": [
"编译 C++(评测版)"
],
"dependsOrder": "sequence",
"presentation": {
"reveal": "always",
"panel": "shared",
"clear": true,
"focus": true
},
"problemMatcher": []
},
{
"label": "仅运行 C++",
"type": "shell",
"command": "${fileDirname}/${fileBasenameNoExtension}",
"options": {
"cwd": "${fileDirname}"
},
"presentation": {
"reveal": "always",
"panel": "shared",
"clear": true,
"focus": true
},
"problemMatcher": []
},
{
"label": "运行 Python",
"type": "shell",
"command": "python3",
"args": [
"${file}"
],
"options": {
"cwd": "${fileDirname}"
},
"presentation": {
"reveal": "always",
"panel": "shared",
"clear": true,
"focus": true
},
"problemMatcher": []
}
]
}
windows 中:
{
"version": "2.0.0",
"tasks": [
{
"label": "编译 C++(评测版)",
"type": "shell",
"command": "g++",
"args": [
"-std=c++14",
"-O2",
"-Wall",
"-Wextra",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-static-libgcc",
"-static-libstdc++"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "silent",
"panel": "shared",
"clear": true
}
},
{
"label": "运行 C++",
"type": "shell",
"command": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"options": {
"cwd": "${fileDirname}"
},
"dependsOn": [
"编译 C++(评测版)"
],
"dependsOrder": "sequence",
"presentation": {
"reveal": "always",
"panel": "shared",
"clear": true,
"focus": true
},
"problemMatcher": []
},
{
"label": "运行 Python",
"type": "shell",
"command": "python",
"args": [
"${file}"
],
"options": {
"cwd": "${fileDirname}"
},
"presentation": {
"reveal": "always",
"panel": "shared",
"clear": true,
"focus": true
},
"problemMatcher": []
}
]
}
一键编译运行
Preferences: Open Keyboard Shortcuts (JSON)
[
{
"key": "ctrl+shift+b",
"command": "workbench.action.tasks.build",
"when": "resourceLangId == cpp"
},
{
"key": "ctrl+f5",
"command": "workbench.action.tasks.runTask",
"args": "运行 C++",
"when": "resourceLangId == cpp"
},
{
"key": "ctrl+alt+r",
"command": "workbench.action.tasks.runTask",
"args": "仅运行 C++",
"when": "resourceLangId == cpp"
},
{
"key": "ctrl+alt+p",
"command": "workbench.action.tasks.runTask",
"args": "运行 Python",
"when": "resourceLangId == python"
},
{
"key": "ctrl+alt+z",
"command": "glassit.increase"
},
{
"key": "ctrl+alt+c",
"command": "glassit.decrease"
}
]
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "调试 C++(开栈 512MB)",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "编译 C++(调试版)",
"setupCommands": [
{
"description": "启用 shell 启动,使 ulimit 生效",
"text": "-gdb-set startup-with-shell on",
"ignoreFailures": true
},
{
"description": "设置栈大小为 512MB(524288 KB)",
"text": "-gdb-set exec-wrapper sh -c 'ulimit -s 524288 && exec \"$@\"' --",
"ignoreFailures": true
},
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
颜色配置
Preferences: Open User Settings (JSON)
{
"vs64.showWelcome": false,
"code-runner.runInTerminal": true,
"editor.fontSize": 20,
"cmake.showOptionsMovedNotification": false,
"code-runner.executorMapByGlob": {
"pom.xml": "cd $dir && mvn clean package"
},
"workbench.colorTheme": "Dark Modern",
"files.autoSave": "afterDelay",
"editor.mouseWheelZoom": true,
"editor.detectIndentation": false,
"editor.insertSpaces": false,
"terminal.integrated.enableMultiLinePasteWarning": "never"
}
{
"workbench.colorCustomizations": {
"editorCursor.foreground": "#ffffff",
"editorCursor.background": "#ffffff",
"editor.lineHighlightBackground": "#30cfff1e",
"editor.lineHighlightBorder": "#30cfff1e",
"editor.findMatchBackground": "#ffeb3b7a",
"editor.findMatchBorder": "#ffeb3b7a",
"editor.findMatchHighlightBackground": "#B3E5FC44",
"editor.findMatchHighlightBorder": "#03A9F4",
"editorBracketHighlight.foreground1": "#fffb00cb",
"editorBracketHighlight.foreground2": "#7bff00d0",
"editorBracketHighlight.foreground3": "#00aeffcb",
"editorBracketHighlight.foreground4": "#8c00ffc2",
"editorBracketHighlight.foreground5": "#ff00aac6",
"editorBracketHighlight.foreground6": "#ff8800d0",
"editorBracketHighlight.unexpectedBracket.foreground": "#FF0000",
"editorBracketMatch.background": "#5c5c5c",
"editorBracketMatch.border": "#5c5c5c",
"terminalCursor.foreground": "#ffffff",
"terminalCursor.background": "#ffffff"
}
}
{
"vs64.showWelcome": false,
"code-runner.runInTerminal": true,
"editor.fontSize": 20,
"editor.lineHeight": 30,
"cmake.showOptionsMovedNotification": false,
"code-runner.executorMapByGlob": {
"pom.xml": "cd $dir && mvn clean package"
},
"workbench.colorTheme": "Dark Modern",
"files.autoSave": "afterDelay",
"editor.mouseWheelZoom": true,
"editor.detectIndentation": false,
"editor.insertSpaces": false,
"terminal.integrated.enableMultiLinePasteWarning": "never",
"workbench.colorCustomizations": {
"activityBar.background": "#0D1117",
"activityBar.foreground": "#39C5BB",
"activityBar.inactiveForeground": "#484F58",
"activityBarBadge.background": "#39C5BB",
"activityBarBadge.foreground": "#0D1117",
"sideBar.background": "#0D1117",
"sideBar.foreground": "#C9D1D9",
"sideBarTitle.foreground": "#39C5BB",
"sideBarSectionHeader.background": "#161B22",
"sideBarSectionHeader.foreground": "#58A6FF",
"editor.background": "#0D1117",
"editor.foreground": "#FFFFFF",
"editorLineNumber.foreground": "#484F58",
"editorLineNumber.activeForeground": "#39C5BB",
"editorCursor.foreground": "#39C5BB",
"editor.selectionBackground": "#39C5BB44",
"editor.inactiveSelectionBackground": "#39C5BB22",
"editor.lineHighlightBackground": "#161B22",
"editor.findMatchBackground": "#39C5BB66",
"editor.findMatchHighlightBackground": "#39C5BB44",
"editorWhitespace.foreground": "#21262D",
"editorIndentGuide.background1": "#21262D",
"editorIndentGuide.activeBackground1": "#39C5BB",
"editorBracketMatch.background": "#39C5BB33",
"editorBracketMatch.border": "#39C5BB",
"editorGutter.background": "#0D1117",
"editorGroup.border": "#21262D",
"editorOverviewRuler.border": "#21262D",
"editorError.foreground": "#F85149",
"editorWarning.foreground": "#D29922",
"editorInfo.foreground": "#39C5BB",
"editorHint.foreground": "#39C5BB",
"statusBar.background": "#0A192F",
"statusBar.foreground": "#FFFFFF",
"statusBar.noFolderBackground": "#0D1117",
"statusBar.debuggingBackground": "#39C5BB",
"statusBar.debuggingForeground": "#0A192F",
"tab.activeBackground": "#0D1117",
"tab.activeForeground": "#FFFFFF",
"tab.inactiveBackground": "#0D1117",
"tab.inactiveForeground": "#5A8A9A",
"tab.border": "#161B22",
"tab.activeBorderTop": "#39C5BB",
"panel.background": "#0D1117",
"panel.border": "#21262D",
"panelTitle.activeForeground": "#39C5BB",
"panelTitle.inactiveForeground": "#484F58",
"terminal.background": "#0D1117",
"terminal.foreground": "#FFFFFF",
"terminal.ansiBlack": "#0D1117",
"terminal.ansiRed": "#F85149",
"terminal.ansiGreen": "#39C5BB",
"terminal.ansiYellow": "#D29922",
"terminal.ansiBlue": "#58A6FF",
"terminal.ansiMagenta": "#BC8CFF",
"terminal.ansiCyan": "#39C5BB",
"terminal.ansiWhite": "#FFFFFF",
"terminal.ansiBrightBlack": "#484F58",
"terminal.ansiBrightRed": "#FF7B72",
"terminal.ansiBrightGreen": "#39C5BB",
"terminal.ansiBrightYellow": "#E3B341",
"terminal.ansiBrightBlue": "#79C0FF",
"terminal.ansiBrightMagenta": "#D2A8FF",
"terminal.ansiBrightCyan": "#39C5BB",
"terminal.ansiBrightWhite": "#FFFFFF",
"button.background": "#39C5BB",
"button.foreground": "#0A192F",
"button.hoverBackground": "#4DB6AC",
"input.background": "#161B22",
"input.foreground": "#FFFFFF",
"input.border": "#21262D",
"inputOption.activeBorder": "#39C5BB",
"dropdown.background": "#161B22",
"dropdown.foreground": "#FFFFFF",
"dropdown.border": "#21262D",
"list.activeSelectionBackground": "#39C5BB33",
"list.activeSelectionForeground": "#FFFFFF",
"list.hoverBackground": "#161B22",
"list.highlightForeground": "#39C5BB",
"scrollbarSlider.background": "#39C5BB33",
"scrollbarSlider.hoverBackground": "#39C5BB55",
"scrollbarSlider.activeBackground": "#39C5BB88",
"badge.background": "#39C5BB",
"badge.foreground": "#0A192F",
"progressBar.background": "#39C5BB",
"editorWidget.background": "#161B22",
"editorWidget.border": "#21262D",
"editorSuggestWidget.background": "#161B22",
"editorSuggestWidget.border": "#21262D",
"editorSuggestWidget.selectedBackground": "#39C5BB33",
"editorHoverWidget.background": "#161B22",
"editorHoverWidget.border": "#21262D",
"peekView.border": "#39C5BB",
"peekViewEditor.background": "#0D1117",
"peekViewResult.background": "#0D1117",
"gitDecoration.addedResourceForeground": "#39C5BB",
"gitDecoration.modifiedResourceForeground": "#58A6FF",
"gitDecoration.deletedResourceForeground": "#F85149",
"gitDecoration.untrackedResourceForeground": "#39C5BB",
"gitDecoration.ignoredResourceForeground": "#484F58"
},
"editor.tokenColorCustomizations": {
"comments": "#5A7A8A",
"strings": "#80CBC4",
"keywords": "#26C6DA",
"numbers": "#4DD0E1",
"types": "#80DEEA",
"functions": "#00BFA5",
"variables": "#FFFFFF",
"textMateRules": [
{
"scope": ["comment", "punctuation.definition.comment"],
"settings": {
"foreground": "#5A7A8A",
"fontStyle": "italic"
}
},
{
"scope": ["string", "punctuation.definition.string"],
"settings": {
"foreground": "#80CBC4"
}
},
{
"scope": ["keyword", "storage.type", "storage.modifier"],
"settings": {
"foreground": "#26C6DA",
"fontStyle": "bold"
}
},
{
"scope": ["entity.name.function", "support.function"],
"settings": {
"foreground": "#00BFA5"
}
},
{
"scope": ["variable", "variable.parameter"],
"settings": {
"foreground": "#FFFFFF"
}
},
{
"scope": ["constant.numeric", "constant.language"],
"settings": {
"foreground": "#4DD0E1"
}
},
{
"scope": ["entity.name.type", "support.type", "support.class", "storage.type"],
"settings": {
"foreground": "#80DEEA"
}
},
{
"scope": ["constant.other", "variable.language"],
"settings": {
"foreground": "#00BCD4"
}
},
{
"scope": ["keyword.operator"],
"settings": {
"foreground": "#6A8A9A"
}
},
{
"scope": ["punctuation", "meta.brace"],
"settings": {
"foreground": "#6A8A9A"
}
},
{
"scope": ["markup.heading"],
"settings": {
"foreground": "#26C6DA",
"fontStyle": "bold"
}
},
{
"scope": ["markup.bold"],
"settings": {
"fontStyle": "bold"
}
},
{
"scope": ["markup.italic"],
"settings": {
"fontStyle": "italic"
}
}
]
},
"background.enabled": true,
"background.editor": {
"images": [
"/usr/share/backgrounds/vscode-bg.jpg"
],
"useFront": false,
"style": {
"background-position": "center center",
"background-size": "cover",
"opacity": 0.08,
"background-repeat": "no-repeat"
}
}
}