vscode基本使用

vscode基本使用

  • vscode基本使用
    • python环境配置
    • c/c++环境配置
    • 通用的执行环境配置

vscode基本使用

python环境配置

  1. 在插件栏目安装python插件
  2. 在当前目目录新建.vscode\settings.json配置python路径如下:
{
   "python.pythonPath": "D:\\APP\\Anaconda3\\envs\\py37\\python.exe"
}
  1. 在当前目目录新建.vscode\launch.json配置python-debug如下:
{
   // Use IntelliSense to learn about possible attributes.
   // Hover to view descriptions of existing attributes.
   // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
   "version": "0.2.0",
   "configurations": [
       {
           "name": "Python: 当前文件",
           "type": "python",
           "request": "launch",
           "program": "${file}",
           "console": "integratedTerminal"
       }
   ]
}
  1. 点击顶部的Debug–>start Debugging即可

c/c++环境配置

  1. 在插件栏目安装c/c++插件
    在这里插入图片描述
  2. 在系统环境中配置环境变量MinGW\\bin
  3. 在vscode中ctr+shift+P,选择C/C++: select a configuration... —> 编辑配置json,最终生成
    在这里插入图片描述
  4. 在main.c中ctr+shift+P,选择C/C++: Buid and Debug Activate file —> gcc.exe 生成和调试文件,最终生成
    vscode基本使用_第1张图片
    即此时就可以调试和运行c/c++程序,接下来通过配置debug方式避免每次都ctr+shift+P启动调试程序
    (1)修改tasks.json的 “label”: “gcc123”
{
    "tasks": [
        {
            "type": "shell",
            "label": "gcc123",
            "command": "D:\\APP\\MinGW\\bin\\gcc.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "D:\\APP\\MinGW\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
        {
            "type": "shell",
            "label": "gcc.exe build active file",
            "command": "D:\\APP\\MinGW\\bin\\gcc.exe",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "D:\\APP\\MinGW\\bin"
            }
        }
    ],
    "version": "2.0.0"
}

(2)点击左侧的Debug按钮 —》点击设置(open launch.json)。。。添加–》c/c++ (gdb) 启动
vscode基本使用_第2张图片
如下

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/src/main.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\APP\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "gcc123"
        },
        {
            "name": "Python: 当前文件",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

注意:
(1)"preLaunchTask": "gcc123"tasks.json的 “label”: "gcc123"保持一致;
(2)“program”: "${workspaceFolder}/src/main.exe"路径修改为自己的
(3) “miDebuggerPath”: “D:\APP\MinGW\bin\gdb.exe”,路径修改为自己的

  1. debug的方式运行
    vscode基本使用_第3张图片

通用的执行环境配置

  1. 在插件栏目安装插件
    vscode基本使用_第4张图片
  2. 修改settings.json(这里主要修改python的运行"code-runner.executorMap":)
{
    "python.pythonPath": "D:\\APP\\Anaconda3\\envs\\py37\\python.exe",
    "code-runner.runInTerminal": true,
    "code-runner.saveFileBeforeRun": true,
    "code-runner.executorMap": {
        "python": "D:\\APP\\Anaconda3\\envs\\py37\\python.exe -u"
    }
}

python的运行也可以先自己激活相应的虚拟环境,然后执行run-code
vscode基本使用_第5张图片

你可能感兴趣的:(vscode)