VS Code 配置记录

VS Code 的配置记录。

全局配置

编辑器配置

1
2
3
4
5
6
7
{
"window.reopenFolders": "all",
"editor.fontSize": 15,
"editor.tabSize": 2,
"editor.formatOnType": true,
"extensions.autoUpdate": true
}

git

  • git 扩展默认开启,修改 git.pathgit.autofetch

终端集成

  • 配置 "terminal.integrated.shell.windows": "C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"

C/C++

  • 安装 c/c++c/c++ clangclang-format 插件。
  • 安装 Native Debug 插件。
  • launch.json 用来配置启动任务,修改 launch.json 来配置调试:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch (GDB)", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", // 配置类型,这里只能为cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"launchOptionType": "Local", // 调试器启动类型,这里只能为Local
"targetArchitecture": "x86", // 生成目标架构,一般为x86或x64,可以为x86, arm, arm64, mips, x64, amd64, x86_64
"program": "${file}.exe", // 将要进行调试的程序的路径
"miDebuggerPath":"path/to/gdb.exe",
// miDebugger的路径,注意这里要与MinGw的路径对应
"args": ["blackkitty", "1221", "# #"], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false
"cwd": "${workspaceRoot}", // 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录
"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
"preLaunchTask": "g++"   // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc
}
]
}
  • Ctrl + Shift + P,输入 Run Build Tasks,配置 tasks.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"version": "0.1.0",
"command": "g++",
"args": ["-g","${file}","-o","${file}.exe"], // 编译命令参数
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
  • 自动补全:Ctrl + Shift + P 输入 settings 打开用户设置,配置 clang.executableclang.cflagsclang.cxxflags
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"clang.cxxflags": [
"-std=c++1y",
"-Wall",
"-I/mingw64/include",
"-I/mingw64/x86_64-w64-mingw32/include",
"-I/mingw64/lib/gcc/x86_64-w64-mingw32/6.3.0/include",
"-I${workspaceRoot}/include",
"-I${cwd}"
],
"clang.cflags": [
"-std=c99",
"-Wall",
"-I/mingw64/include",
"-I/mingw64/x86_64-w64-mingw32/include",
"-I/mingw64/lib/gcc/x86_64-w64-mingw32/6.3.0/include",
"-I${workspaceRoot}/include",
"-I${cwd}"
],
"clang.executable": "/mingw64/bin/clang.exe"
  • 配置 cpptoolsc_cpp_properties.json,将对应系统的 include 项修改为 settings.json 中相同的几个路径。
  • F8 可生成目标文件和可执行文件,按 F5 启动调试。

HTML

  • 标签自动关闭可安装插件 Auto Close Tag
  • 根据开始标签自动修改关闭标签可安装插件 Auto Rename Tag

Go

  • Go 语言有唯一的插件可以安装。需要手动 go get 所需的工具。

Python

  • 安装 Python 插件,配置一下 python.pythonPath 就可以使用。

主题、配色

  • Ctrl + Shift + P 输入 File Icon Theme 可以修改图标主题。
  • Code Runner 可以选中一行/几行代码并右击运行,功能非常强大,用处比较大。
  • 需要在文件头部加上固定内容可以使用插件 vscode-file-header-comment-helper
  • 改背景图 Background
  • 彩虹括号 Rainbow Brackets
  • Project Manager 可在多个 git 项目之间切换。
  • File Peeker 可点击编辑内容中的文件名并打开文件。
  • Path Intellisense 可自动补全路径。

参考资料:

原创作品,允许转载,转载时无需告知,但请务必以超链接形式标明文章原始出处(http://blog.forec.cn/2017/01/31/vscode-configuration/) 、作者信息(Forec)和本声明。

分享到