VS Code plug-ins recommended and C / C ++ configuration

Here is what I often use the VS Code plug-ins. Since the plug-in itself has a detailed configuration and presentation, installation and configuration plug-in itself not be explained, only the main function of spending these plug-ins. Specific use is strongly recommended to look at post-installation instructions the plug, most of the problems and settings can be found, not because it is in English directly to search the Internet.

VS Code Configuration Synchronization

settings sync

 Current settings sync tips have been very smart, when the first use will be prompted to log on github, unauthorized access can be. Log github, click the plus sign in the upper right corner, click New gist (need some Internet skills, or can not open the page)

After the new gist input settings sync configuration can be.

C++

Both plug-ins can be written in C ++ makes it easier. It has a powerful auto-complete function. About C ++ specific configuration will explain in detail below.

beautify

Themes and icons I recommend using the following two plug-ins. First Material Theme plugin mainly to change the background color, font and syntax highlighting. The second paragraph of plug-ins can make the icons file structure clearer. Chinese Chinese plug-configured Required.

Bracket highlighting

git

I recommend using gitlens. gitlens incredibly powerful, just the tip of the iceberg icon its function, it can even show a part of who change the code to do at what time.

tab function expansion

tabout plug can be made out directly from the bracket tab key or click quotes, no need to press the direction key or the end key.

cmake

cmake function such CMakeLists.txt writing becomes easy, with automatic completion and highlighting.

Dictionary translation

xmake

xmake is a similar cmake cross-platform automation software compiler development of the people. Personally I think its language support (support cuda) more abundant. Are interested can take a look, to support the development of people. URL: https: //xmake.io/#/zh-cn/

After vscode installation xmake plug-in, you can easily do the compilation. Note that you need to install xmake, and then install the plugin.

C / C ++ configuration

Whether it is Linux or Windows, user profiles are placed in .vscode. Explain here the user configuration and the global configuration. A user profile is for a special project or folder and do. All configuration files are placed .vscode hidden files in the folder in the folder.

Global configuration is as shown in FIG inlet. Here all configuration changes will be visible in any file folder.

Windows

Paste the first configuration, after the explanations for each file.

c_cpp_properties.json configuration is as follows:

{
    "configurations": [
        {
            "name": "MinGW",
            "compilerPath": "C:\\MinGW\\bin\\g++.exe",
            "includePath": [
                "${workspaceFolder}"
            ],
            "defines": [],
            "browse": {
                "path": [
                    "${workspaceFolder}"
                ],
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            },
            "cStandard": "c11",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}

launch.json:

Https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md //
{
    "Version": "0.2.0",
    "Configurations": [
        {
            "name": "(GDB) the Launch" // configuration name will appear in the drop-down menu to start the configuration of the
            "type": "cppdbg", // type of configuration, this can only be cppdbg
            "request": "launch", // request configuration type, which can be launch (start) or attach (additional)
            paths "$ {fileDirname} / $ { fileBasenameNoExtension} .exe", // the program to be debugged: "program"
            "args": [], // passed to debugging command line parameters, usually set to be empty
            "stopAtEntry": false, // set to true when the program will be suspended at the entrance to the program, I generally set to true
            "CWD": " $ {workspaceFolder} ", // working directory when debugging program
            " environment ": [], // ( environment variables?)
            "externalConsole": true, // whether to display the console window when debugging, generally set the display console to true
            "internalConsoleOptions": "neverOpen", // If you do not set neverOpen, will jump to "Debug Console" option when debugging card, you should not need to manually enter the gdb command, right?
            "MIMode": "gdb", // specify debugger connection may gdb or lldb. But lldb in the windows is not pre-compiled version.
            "miDebuggerPath": "gdb.exe", // debugger path suffix can not be omitted under Windows, Linux, then remove the
            "preLaunchTask": tasks performed before the start of "build" // debugging session, usually the compiler. The label and corresponding tasks.json
        }
    ]
}

setting.json:

{
    "files.associations": {
        "iostream": "cpp"
    }
}

tasks.json:

// https: //code .visualstudio.com /docs/editor/tasks
{
    "version" : "2.0.0" ,
    "tasks" : [
        {
            "label" : "build" , // 任务名称,与launch.json的preLaunchTask相对应
            "command" : "g++" , // 要使用的编译器
            "args" : [
                "-g" , // 生成和调试有关的信息
                "${file}" ,
                "-o" , // 指定输出文件名,不加该参数则默认输出a.exe,Linux下默认a.out
                "${fileDirname}\\${fileBasenameNoExtension}.exe" ,
                // "${fileDirname}/${fileBasenameNoExtension}.exe" ,
            ], // 编译命令参数
            "type" : "shell" , // 可以为shell或process,前者相当于先打开shell再输入命令,后者是直接运行命令
            "group" : {
                "kind" : "build" ,
                "isDefault" : true // 设为 false 可做到一个tasks.json配置多个编译指令,需要自己修改本文件,我这里不多提
            },
            "problemMatcher" :{
                "owner" : "$gcc" ,
                "fileLocation" : "absolute" ,
                "pattern" :[
                    {
                        "regexp" : "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$" ,
                        "file" : 1,
                        "line" : 2,
                        "column" : 3,
                        // "location" : 2,
                        "message" : 5
                    }
                ]
              }
        }
    ]
}

Linux

launch.json

{
    // 使用 IntelliSense 了解相关属性。
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https: //go .microsoft.com /fwlink/ ?linkid=830387
    "version" : "0.2.0" ,
    "configurations" : [
        {
            "name" : "gcc build and debug active file" ,
            "type" : "cppdbg" ,
            "request" : "launch" ,
            "program" : "${fileDirname}/${fileBasenameNoExtension}" ,
            "args" : [],
            "stopAtEntry" : false ,
            "cwd" : "${workspaceFolder}" ,
            "environment" : [],
            "externalConsole" : false ,
            "MIMode" : "gdb" ,
            "setupCommands" : [
                {
                    "description" : "Enable pretty-printing for gdb" ,
                    "text" : "-enable-pretty-printing" ,
                    "ignoreFailures" : true
                }
            ],
            "preLaunchTask" : "gcc build active file" ,
            "miDebuggerPath" : "/usr/bin/gdb"
        }
    ]
}

tasks.json

{
// 有关 tasks.json 格式的文档,请参见
    // https: //go .microsoft.com /fwlink/ ?LinkId=733558
    "version" : "2.0.0" ,
    "tasks" : [
        {
            "type" : "shell" ,
            "label" : "gcc build active file" ,
            "command" : "/usr/bin/gcc" ,
            "args" : [
                "-g" ,
                "${file}" ,
                "-o" ,
                "${fileDirname}/${fileBasenameNoExtension}" ,
                "-l" ,
                "pthread"
            ],
            "options" : {
                "cwd" : "/usr/bin"
            },
            "problemMatcher" : [
                "$gcc"
            ]
        }
    ]
}

Configuration instructions

Under normal circumstances, debug process c ++ is that, first of vscode call launch.json, launch.json according to "preLaunchTask": "gcc build active file",the name of the call, called "gcc build active file"task.json of task.json can have multiple task, according to the tasks of the label name to call the corresponding task. The main task is responsible compiled into an executable file. If you only need to generate an executable file, press crtl+shift+bcan be.

c_cpp_properties mainly specialized configurations for c / c ++ compiler, such as include paths.

It is strongly recommended to see the json in English, its description is very easy to understand. The process of c ++ compiler for Linux-based somewhat anyone can quickly grasp and private custom.

See detailed vscode configure Microsoft . Microsoft is strongly recommended to see the docs explain, although it looks reading time-consuming, but far more than you search the Internet all kinds of information more quickly. Because even if you successfully set up, in accordance with my configuration when applied to different projects or language, it may be difficult to configure.

Guess you like

Origin www.linuxidc.com/Linux/2019-11/161367.htm