VS code 插件配置手册

来源:OpenCV学堂

本文约4100字,建议阅读8分钟 本文为你介绍了常见的插件配置问题。


VS code 插件配置手册

C/C++ Tools插件---C/C++支持

安装

库文件的配置

GDB本地调试配置

GDB远程调试配置

Remote VSCode插件---远程编辑文件

安装

环境配置

在本地端的配置

在远程端的配置

工作流

Ftp Sync插件--—远程代码的同步

安装

环境配置

工作流

C/C++ Tools插件---C/C++支持

此扩展的预览版本为C / C ++添加了对Visual Studio Code的语言支持,包括:

语言服务:

  • 代码格式(clang格式)

  • 自动补全

  • 符号搜索

  • 签名帮助

  • 快速信息

  • 转到定义/声明

  • 查看定义/声明

  • 类/方法导航

调试:

  • 支持调试Windows、Linux和macOS应用程序

  • 断点

  • 变量查看

  • 逐行代码调试

  • 支持多线程调试

  • 支持核心转储调试


安装

在VSCode的扩展插件中找到C/C++插件并进行安装; 

Windows下想开发Linux代码需要安装Mingw开发工具

库文件的配置

打开项目到工作区,

按F1打开命令行,输入:

open settings json

选择Preferences:Opem Settings (JSON),打开settings.json文件

在settings.json文件中添加:

/*****C/C++ Tools*****/
"C_Cpp.autocomplete": "Default",
"[cpp]": {
    "editor.quickSuggestions": true
},
"[c]": {
    "editor.quickSuggestions": true
},
"C_Cpp.default.cStandard": "c11",
"C_Cpp.default.cppStandard": "c++11",
/*****C/C++ Tools*****/

按F1打开命令行,输入:

edit configuration json

选择C/C++:Edit configurations (JSON),打开c_cpp_properties.json文件

在settings.json文件中添加:

{
    "configurations": [
        {
            "name": "system",                //系统类型
            "includePath": [                //头文件目录,**表示匹配目录文件及子目录
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "path",            //编译器地址
            "intelliSenseMode": "mode"        //编译器类型 
            "cStandard": "c11",
            "cppStandard": "c++11"
        }
    ],
    "version": 4
}

如:

Windows :

{
    "configurations": [
        {
            "name": "Win32",                
            "includePath": [                
                "${workspaceFolder}/**",
                "C:/opencv/build/include/opencv2/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "intelliSenseMode": "msvc-x64",
            "cStandard": "c11",
            "cppStandard": "c++11"
        }
    ],
    "version": 4
}

Linux:

{
    "configurations": [
        {
            "name": "Linux",                
            "includePath": [                
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "intelliSenseMode": "clang-x64",
            "cStandard": "c11",
            "cppStandard": "c++11"
        }
    ],
    "version": 4
}

GDB本地调试配置

打开项目到工作区,

打开侧栏的“调试”界面->点击“设置”按钮,选择C++(GDB/LLDB)选项:

打开launch.json文件,在文件中添加:

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",        // 配置名称,将会在启动配置的下拉菜单中显示
            "type": "cppdbg",            // 配置类型,不需修改 
            "request": "launch",        // 请求配置类型,可以为launch(启动)或attach(附加)  
            "program": "${workspaceFolder}/bin文件",    // 将要进行调试的程序的路径 
            "args": [],                    // 程序调试时传递给程序的命令行参数,["arg1", "arg2]. 
            "stopAtEntry": false,        // 设为true时程序将暂停在程序入口处,一般设置为false 
            "cwd": "${workspaceFolder}",        // 程序调试程序时要搜索的代码的目录
            "additionalSOLibSearchPath": "path" // 程序调试程序时要搜索的.so文件的目录(选填)
            "environment": [],            // 针对调试的程序,要添加到环境中的环境变量(选填)
            "externalConsole": true,    // 调试时是否显示控制台窗口,一般设置为true显示控制台 
            "MIMode": "gdb",            // VSCode要使用的调试工具,必须设置为gdb或lldb
            "miDebuggerPath": "path",    // VSCode要使用的调试工具路径(需要绝对路径)
            "preLaunchTask": "g++",     // 调试开始前执行的任务,需要配置tasks.json文件(选填)
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

如:

Windows:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",        
            "type": "cppdbg",            
            "request": "launch",
            "program":"${workspaceRoot}/bin/pthread.exe",    
            "args": [],                    
            "stopAtEntry": false,        
            "cwd": "${workspaceFolder}",    
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe"
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

Linux:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb local) L",        
            "type": "cppdbg",            
            "request": "launch",         
            "program": "${workspaceFolder}/bin/pthread",    
            "args": [],                    
            "stopAtEntry": false,        
            "cwd": "${workspaceFolder}",        
            "externalConsole": true,    
            "MIMode": "gdb",            
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

打开侧栏的“调试”界面->点击“开始调试”按钮,开始调试

GDB远程调试配置

打开项目到工作区,

打开侧栏的“调试”界面->点击“设置”按钮,选择C++(GDB/LLDB)选项:

打开launch.json文件,在文件中添加:

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",        // 配置名称,将会在启动配置的下拉菜单中显示
            "type": "cppdbg",            // 配置类型,不需修改 
            "request": "launch",        // 请求配置类型,可以为launch(启动)或attach(附加)  
            "program": "${workspaceFolder}/bin文件",    // 将要进行调试的程序的路径  
            "args": [],                    // 程序调试时传递给程序的命令行参数,["arg1", "arg2]. 
            "stopAtEntry": false,        // 设为true时程序将暂停在程序入口处,一般设置为false 
            "cwd": "${workspaceFolder}",        // 程序调试程序时的代码所在的目录
            "additionalSOLibSearchPath": "path",// 程序调试程序时要搜索的.so文件的目录(选填)
            "environment": [],            // 针对调试的程序,要添加到环境中的环境变量(选填)
            "externalConsole": true,    // 调试时是否显示控制台窗口,一般设置为true显示控制台 
            "MIMode": "gdb",            // VSCode要使用的调试工具,必须设置为gdb或lldb
            "miDebuggerPath": "path",    // VSCode要使用的调试工具路径(需要绝对路径)
            /**********与本地调试不同的地方**********/
            "miDebuggerServerAddress": "addr:port",    // 要远程调试的地址,IP地址:端口号
            "debugServerArgs": "args",                // 调试器服务器的参数        
            /**********与本地调试不同的地方**********/
            "preLaunchTask": "g++",     // 调试开始前执行的任务,需要配置tasks.json文件(选填)
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

如:

Linux:

{
    "version": "0.2.0",
    "configurations": [
      {
            "name": "(gdb server) L",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/bin/pthread",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "externalConsole": true,
            "MIMode": "gdb",
           /**********与本地调试不同的地方**********/
            "miDebuggerServerAddress": "192.168.0.100:2333",
              "debugServerArgs": "",
           /**********与本地调试不同的地方**********/
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

先远程端:

打开一个新终端,运行gdbserver打开要调试的程序:

gdbserver localhost:port bin文件路径(与launch.json文件配置路径相同)

如:

gdbserver localhost:2333 ./bin/pthread

若想关闭gdbserver,需要在远程打开新终端,输入:

killall gdbserver  

再在本地端:


打开侧栏的“调试”界面->点击“开始调试”按钮,开始调试

Remote VSCode插件---远程编辑文件

此扩展允许您轻松地获取并编辑远端文件,而不是使用命令行和 vi 编辑远端文件这种原始的操作。

安装

在VSCode的扩展插件中找到Remote VSCode插件并进行安装; 

环境配置

在本地端的配置

右键点击“Remote VSCode插件”->“配置扩展设置”,在设置页面设置相应参数:

Remote:Host(本地IP地址)设置为:127.0.0.1

Remote:Port(本地通信端口)设置为:52698

Remote:Onstartup(插件自启动)设置为:false

Remote:Dont Show Port Already In Use Error(端口正在使用时不报错)设置为:false

或者,按F1打开命令行,输入:

open settings json

选择Preferences:Opem Settings (JSON),打开settings.json文件

在settings.json文件中添加:

/*****Remote VSCode*****/
"remote.host": "127.0.0.1",
"remote.port": 52698,
"remote.onstartup": false,
"remote.dontShowPortAlreadyInUseError": false,
/*****Remote VSCode*****/

在远程端的配置

远程Linux安装 rmate:

wget https://raw.githubusercontent.com/sclukey/rmate-python/master/bin/rmate

chmod +x ./rmate

mv ./rmate /usr/local/bin/rmate

工作流

启动插件

按F1打开命令行,输入:

remote:start server

选择Remote:Start Server,开启插件

附件:

使用命令行:

remote:start server :开启插件
remote:stop server :关闭插件

连接远程系统,传输编辑文件:

本地:

打开上方工具栏”终端”->“新建终点”,或按ctrl + shift + `快捷键,打开PowerShell终端:

在终端窗口中输入:

ssh -R 52698:127.0.0.1:52698 远端用户名@远端地址

如:

ssh -R 52698:127.0.0.1:52698 linux@192.168.0.111

之后输入密码ssh连接远程Linux系统即可。

远端:

在远端终端中输入:

rmate -p 52698 打开要编辑的文件

如:

rmate -p 52698 ./main.cpp


Ftp Sync插件--—远程代码的同步

此扩展允许您轻松地将项目文件 通过FTP与远端同步。

安装

在VSCode的扩展插件中找到Ftp-Sync插件并进行安装; 

环境配置

新建一个目录,并打开到工作区

按F1打开命令行,输入:

ftp-sync

选择Ftp-sync: Init ,新建并打开ftp-sync.json文件,初始化配置

在ftp-sync.json文件中配置:

{
    "remotePath": "path",        //要传输的文件的远端站点的目录
    "host": "host",                //远端地址
    "username": "username",        //远端用户名
    "password": "password",        //远端密码
    "protocol": "sftp",         //sftp协议,默认值为ftp协议
    "port": 22,                 //ftp默认端口是21,sftp的默认端口是22
    "uploadOnSave": false,        //是否应该自动保存上传文件,默认值为false
    "secure": false,            //安全设置,默认值为false
    "ignore": [                    //忽略上传路径
        "\\.vscode",
        "\\.git",
        "\\.DS_Store"
    ],
    "passive": false,
    "debug": false,
    "privateKeyPath": null,
    "passphrase": null,
    "agent": null,
    "allow": [],
    "generatedFiles": {
        "extensionsToInclude": [
            ""
        ],
        "path": ""
    }
}

如:

{
    "remotePath": "/home/linux/pro/",    
    "host": "192.168.0.111",            
    "username": "linux",            
    "password": "123456",                
    "protocol": "sftp",                 
    "port": 22,                         
    "uploadOnSave": false,                
    "secure": false,                    
    "ignore": [                            
        "\\.vscode",
        "\\.git",
        "\\.DS_Store"
    ],
    "passive": false,
    "debug": false,
    "privateKeyPath": null,
    "passphrase": null,
    "agent": null,
    "allow": [],
    "generatedFiles": {
        "extensionsToInclude": [
            ""
        ],
        "path": ""
    }
}

工作流

使用命令行:

Ftp-sync: Sync Local to Remote : 本地同步到远程

Ftp-sync: Sync Remote to Local : 远程同步到本地

Ftp-sync: Commit : 提交修改

编辑:王菁

校对:林亦霖

vscode插件合集,05月最新,包括以下插件: bibhasdn.django-html-1.2.0 bibhasdn.django-snippets-1.1.0 bitlang.cobol-1.7.8 christian-kohler.npm-intellisense-1.3.0 christian-kohler.path-intellisense-1.4.2 chrmarti.regex-0.2.0 CoenraadS.bracket-pair-colorizer-1.0.37 daltonjorge.scala-0.0.5 danields761.dracula-theme-from-intellij-pythoned-0.1.4 DavidAnson.vscode-markdownlint-0.17.0 dbaeumer.vscode-eslint-1.4.10 donjayamanne.jupyter-1.1.4 donjayamanne.python-extension-pack-1.0.1 DotJoshJohnson.xml-1.9.2 DotJoshJohnson.xml-2.0.0 eg2.vscode-npm-script-0.3.4 eriklynd.json-tools-1.0.2 fisheva.eva-theme-0.3.1 formulahendry.code-runner-0.9.3 formulahendry.terminal-0.0.10 gerane.theme-druid-0.0.2 GrapeCity.gc-excelviewer-2.0.21 humao.rest-client-0.18.4 humy2833.ftp-simple-0.6.3 Ikuyadeu.r-0.5.9 Ikuyadeu.r-lsp-0.0.7 itryapitsin.scala-0.1.7 itryapitsin.scalasnippets-0.1.7 jasonnutter.search-node-modules-1.3.0 jithurjacob.nbpreviewer-1.0.0 josephtbradley.hive-sql-0.0.2 kalitaalexey.vscode-rust-0.4.2 kondratiev.sshextension-0.2.1 luqimin.forgive-green-0.2.1 magicstack.magicpython-1.0.12 mohsen1.prettify-json-0.0.3 mooman219.rust-assist-0.2.0 ms-python.anaconda-extension-pack-1.0.0 ms-python.python-2018.4.0 ms-toolsai.vscode-ai-0.1.8 ms-vscode.go-0.6.80 mtxr.sqltools-0.13.0 PKief.material-icon-theme-3.4.0 qub.qub-xml-vscode-1.2.8 redhat.java-0.25.0 redhat.vscode-yaml-0.0.12 rust-lang.rust-0.4.3 rust-lang.rust-0.4.4 scala-lang.scala-0.1.2 sensourceinc.vscode-sql-beautify-0.0.4 truman.autocomplate-shell-0.1.1 vahidk.tensorflow-snippets-0.3.3 vscjava.vscode-java-debug-0.9.0 vscjava.vscode-java-pack-0.3.0 vscjava.vscode-java-test-0.6.1 vscjava.vscode-maven-0.8.0 waderyan.nodejs-extension-pack-0.1.9 wholroyd.jinja-0.0.8 xabikos.javascriptsnippets-1.6.0 yzhang.markdown-all-in-one-1.3.0 yzhang.markdown-all-in-one-1.4.0 ZakCodes.rust-snippets-0.0.1 zhuangtongfa.material-theme-2.13.5 zhuangtongfa.material-theme-2.13.6
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值