Visual Studio Code的使用

2022/6/10 23:22:39

本文主要是介绍Visual Studio Code的使用,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.VS code 设置鼠标滚轮滑动设置字体大小

打开"文件->首选项->设置 打开settings.json文件 在setting.json 中添加
"editor.mouseWheelZoom": true

2.VS code 配置C语言

首先下载mingw(由于外网问题,wingw直接下载可能体验不好,建议下载devcpp或codeblocks(带mingw64版本),可以自动安装mingw),下载安装完成后把D:\CodeBlocks\MinGW\bin添加到环境变量,

在想要运行的C语言代码文件夹下建立一个名为“.vscode”的文件夹,在里面新建3个json文件(json内容贴在文末了)

在VS code上安装必要的C/C++等插件,打开C代码所在文件夹,然后ctrl+F5运行想要运行的C代码文件

由于C语言的特殊性,配置过程比较繁琐,并且不能像python一样只需第一次运行时配置(博主尝试过将./vscode文件夹下的几个json文件内容写入vscode默认配置json文件,但是这会影响到python等其它语言的配置环境)

tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-g", 
                "${file}", 
                "-o", 
                "${fileBasenameNoExtension}.exe",
                "-fexec-charset=GBK"//解决中文乱码
            ]
        }
    ],
    "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "shared", 
        "showReuseMessage": true,
        "clear": false
    }
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        //若要运行python:恢复下列配置
        //{
        //    "name": "Python: 当前文件",
        //    "type": "python",
        //    "request": "launch",
        //    "program": "${file}",
        //    "console": "integratedTerminal"
        //},
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "cmd",
            "preLaunchTask": "echo",
            "args": [
                "/C",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "&",
                "echo.",
                "&",
                "pause"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole":true
        },
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "D:\\CodeBlocks\\MinGW\\bin\\gdb.exe",// 自己电脑的gdb
            "preLaunchTask": "echo",//这里和task.json的label相对应
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
 
        }
    ]
}

c_cpp_properties.json

{
  "configurations": [
      {
          "name": "Win32",
          "includePath": [
              "${workspaceRoot}",
              "D:/CodeBlocks/MinGW/include/**",
              "D:/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
              "D:/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
              "D:/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
              "D:/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
              "D:/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
              "D:/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
          ],
          "defines": [
              "_DEBUG",
              "UNICODE",
              "__GNUC__=6",
              "__cdecl=__attribute__((__cdecl__))"
          ],
          "intelliSenseMode": "msvc-x64",
          "browse": {
              "limitSymbolsToIncludedHeaders": true,
              "databaseFilename": "",
              "path": [
                  "${workspaceRoot}",
                  "D:/CodeBlocks/MinGW/include/**",
                  "D:/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
                  "D:/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
                  "D:/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
                  "D:/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
                  "D:/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
                  "D:/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
              ]
          }
      }
  ],
  "version": 4
}

最后,建议初学者编程时文件名(以及路径名)最好不要有中文,以免因编码问题导致乱码

3.VS Code插件

HTML Boilerplate( HTML 模版插件在空文件中输入感叹号!,并按tab键或者enter键即可生成初始干净的文档结构)、HTML CSS SupportHTML Previewvscode-pdfmarkdownlintDraw.io Integration(流程图插件,新建.drawio文件打开即可画流程图)、XML Tools



这篇关于Visual Studio Code的使用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程