VS Code配置部分语言编译环境

写在前面

由于本人喜欢用VS Code这种轻量的编辑器,但是却不能开箱即用,有时重装系统后就要从新配置,所以写下此篇来记录部分语言的配置方法.

C/C++

1.安装gcc等编译器:

下载地址:https://www.mingw-w64.org/downloads/

下载后安装到任意位置,再Windows的环境的path中添加:你的安装的地址/mingw64/bin.

记得要将/bin下的mingw32-make.exe名称改为make.exe,以便make命令能正常使用.

2.VS Code配置:

安装插件:

C

一般安装第一个后面两个就会提示安装.

3.调试配置:

这是我的编译和调试配置:

tasks:

 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
{
    "tasks": [
        {
            "type": "shell",
            "label": "g++ build",
            "command": "C:\\CodePath\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": "$gcc",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": true
            }
        },
        {
            "label": "make build",
            "type": "shell",
            "command": "make",
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": "$gcc",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": true
            }
        }
    ],
    "version": "2.0.0"
}

luanch

 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
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++ g++",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "g++ build"
        },
        {
            "name": "C/C++ make",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "make build"
        }
    ]
}

GO

1.安装GO编译器:

官网地址:https://golang.google.cn/

下载安装msi基本就可以,一般不需要多余的配置.

或者下载.zip结尾的,解压到一个目录,并添加环境变量:

GOROOT:安装目录

GOPATH:任意一个目录,用于存放工具和三方库文件.

在系统环境变量path里添加:%GOROOT%/bin,便完成了安装

一般默认开启了go111module的auto模式,可以使用gopath也可使用gomod来管理.

要调整一下源:

1
2
3
#重新设置成七牛镜像源(推荐)或阿里镜像源(用原有的会比较慢)
go env -w GOPROXY=https://goproxy.cn,direct
go env -w GOPROXY=https://mirrors.aliyun.com/goproxy,direct

2.VS Code配置

安装go语言插件:

Go

再VS Code的命令面板输入Go: install/update tools以安装调试所需依赖.

3.调试配置

这是我的调试配置:

luanch:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Go Debug",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${fileDirname}/${fileBasenameNoExtension}.go",
            "console": "integratedTerminal"
        }
    ]
}

Node.js

1.下载安装Node.js

Node.js官网地址:https://nodejs.org/zh-cn

下载安装,并在安装目录下设立两个文件夹:node_global,node_cache.

配置一下环境变量:

在系统环景变量中添加:NODE_HOME内容为你的安装的地址/nodejs.

在系统环境变量中的path添加:%NODE_home%/node_global%NODE_home%/node_cache.

把用户环境变量中的:C:User/用户名/AppDate/Roaming/npm改为你的安装的地址/nodejs/node_global

执行一下命令:

  • 设置缓存位置

npm config set cache 你的安装的地址/nodejs/node_cache

  • 设置全局模块地址

npm config set prefix 你的安装的地址/nodejs/node_global

换源

执行以下命令换镜像源:

1
npm config set registry http://mirrors.cloud.tencent.com/npm/ #腾讯云

2.VS Code配置

安装一下插件即可:

JS

设置权限

设置安装目录nodejs的权限,开启用户的完全控制权限,并在管理员权限下的powershell执行一下命令:Set-ExecutionPolicy Unrestricted 否者npm会无法安装插件或者VS Code下npm命令无法使用.

JAVA

1.安装JDK:

下载地址:https://www.oracle.com/cn/java/technologies/downloads/

安装所需要的版本.

环境变量配置:

  1. 系统变量添加JAVA_HOME,内容为:jdk安装目录.
  2. 在系统变量path目录下添加:%JAVA_HOME%\bin.

2.VS Code配置

安装这个插件即可(他包含七个插件):

image-20250707175901743

可以直接创建项目,编写运行.

单文件调试配置:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Java Debug",
            "request": "launch",
            "mainClass": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

HTML + CSS +Javascript

一般安装一下插件即可:

html

这两个用来方便编写代码:

Live Server

ART