跳到正文

个人记录

vscode 配置

#SUSPENDED#约 5 分钟
原文

这是 2026年9月18日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年9月16日
收录
2026年9月18日
更新
2026年11月21日
篇幅
约 5 分钟
获赞
1

版本

  1. v4当前
  2. v3
  3. v2
  4. v1

基础设置

打开设置(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 + `),使用以下命令编译运行:

Bash
g++ 文件名.cpp -o 文件名 -std=c++14 -O2 -Wall && ./文件名

方式二:配置 tasks.json 实现一键编译

如需在 VS Code 内按快捷键编译,可创建 .vscode/tasks.json 文件。

JSON
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "编译 C++(评测版)",
      "type": "shell",
      "command": "g++",
      "args": [
        "-std=c++14",
        "-O2",
        "-Wall",
        "-Wextra",
        "-g",
        "-Wl,--stack=1024000000",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}.exe"
      ],
      "options": {
        "cwd": "${fileDirname}",
        "shell": {
          "executable": "C:\\Windows\\System32\\cmd.exe",
          "args": ["/d", "/c"]
        }
      },
      "problemMatcher": ["$gcc"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "presentation": {
        "reveal": "silent",
        "panel": "shared",
        "clear": true
      }
    },
    {
      "label": "编译 C++(调试版)",
      "type": "shell",
      "command": "g++",
      "args": [
        "-std=c++14",
        "-O0",
        "-g",
        "-Wall",
        "-Wextra",
        "-Wl,--stack=1024000000",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}.exe"
      ],
      "options": {
        "cwd": "${fileDirname}",
        "shell": {
          "executable": "C:\\Windows\\System32\\cmd.exe",
          "args": ["/d", "/c"]
        }
      },
      "problemMatcher": ["$gcc"],
      "group": "build",
      "presentation": {
        "reveal": "silent",
        "panel": "shared",
        "clear": true
      }
    },
    {
      "label": "运行 C++",
      "type": "shell",
      "command": "${fileDirname}/${fileBasenameNoExtension}.exe",
      "options": {
        "cwd": "${fileDirname}"
      },
      "dependsOn": ["编译 C++(评测版)"],
      "dependsOrder": "sequence",
      "group": {
        "kind": "test",
        "isDefault": true
      },
      "presentation": {
        "reveal": "always",
        "panel": "shared",
        "clear": true
      },
      "problemMatcher": []
    }
  ]
}

配置后,按 Ctrl+Shift+B 即可编译当前文件。