美文网首页
vscode 配置C/C++开发环境

vscode 配置C/C++开发环境

作者: wayyyy | 来源:发表于2020-03-28 18:47 被阅读0次

ubuntu 18.04 安装vscode

  1. 加上Visual Studio代码存储库与密钥,下载并安装存储库和GPG密钥,以下:
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64]  https://packages.microsoft.com/repos/vscode stable main" >  /etc/apt/sources.list.d/vscode.list'
  1. 更新apt索引并在Ubuntu 18.04下安装Visual Studio Code,运行以下三段命令:
sudo apt-get update
sudo apt-get install apt-transport-https
sudo apt-get install code
rm -rf microsoft.gpg

vscode插件推荐

  • Chinese
    中文语言插件

  • C/C++
    代码补齐,符号跳转。

  • SFTP
    ctrl+shift+p输入sftp config

    {
      "name": "jdy",
      "host": "114.67.xx.xx",
      "protocol": "sftp",
      "port": 22,
      "username": "root",
      "password": "xxx",
      "remotePath": "/root/code/cp_pythonvm",
      "uploadOnSave": false,
      "ignore": [
          ".vscode"
      ]
    }
    
  • trailing spaces
    默认配置,显示文件中的空格,保持文件干净,让空格无处遁形。

  • One Monokai Theme
    主题插件

  • highlight-icemode
    变量高亮插件。

  • Material Icon Theme
    图标美化插件,可以使得文件结构更加清晰。

  • bracket pair colorizer
    给括号上色,避免一层层的括号难看,默认配置就行。

  • Markdown Preview Enhanced
    Markdown 实时预览插件。

  • shell-format
    shell 脚本代码格式化插件。

  • shellman
    shell 脚本代码提示插件。

  • Todo Tree
    跟踪文件的todo,fixme。

  • Bookmarks
    书签插件
    ctrl+alt+K 创建或消除书签
    ctrl+alt+j 跳转到前一个书签
    ctrl+alt+l 跳转到后一个书签

    注意:需要设置一下,支持 在所有文件中跳转。

  • Project Manager
    管理多个项目

  • Local history
    保存vscode编辑文件的历史记录。

  • Code Spell Checker
    代码拼写检查


常用配置

  • 快捷键
    ctrl+b:隐藏 / 显示侧边栏
    Shift+Ctl+O:搜索函数
    ctrl+t:搜索结构体
    ctrl+g:跳转到行
    ctrl+p:跳转到文件
    ctrl+shift+f:全局搜索
  • C/C++ 库文件配置
    ctrl+shift+p输入"C/C++:编辑配置",在.vscode文件夹中的文件 c_cpp_properties.json 配置。
  • 设置文件夹内文件过滤
    https://www.cnblogs.com/langka/p/10470909.html
  • 设置自动猜测文件编码
    文件->首选项->设置
    搜索 files.autoGuessEncoding 打钩 Auto Guess Encoding

将外网插件复制到内网

工作环境中一台外网和一台内网,在内网中安装插件的方法:
https://jingyan.baidu.com/article/359911f581c1a457fe030636.html


工作区配置

在工作文件夹下面新建文件夹".vscode",然后在".vscode"下面新建2个json文件并保存。

  • launch.json
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "C/C++",
                "type": "cppdbg",
                "request": "launch",
                "program": "${fileDirname}/${fileBasenameNoExtension}",
                "args": [],
                "stopAtEntry": false,
                "cwd": "${workspaceFolder}",
                "environment": [],
                "externalConsole": false,
                "MIMode": "gdb",
                "preLaunchTask": "compile",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            }
        ]
    }
    
  • tasks.json
    {
        "version": "2.0.0",
        "tasks": [{
                "label": "compile",
                "command": "g++",
                "args": [
                    "-g",
                    "${file}",
                    "-o",
                    "${fileDirname}/${fileBasenameNoExtension}"
                ],
                "problemMatcher": {
                    "owner": "cpp",
                    "fileLocation": [
                        "relative",
                        "${workspaceRoot}"
                    ],
                    "pattern": {
                        "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                        "file": 1,
                        "line": 2,
                        "column": 3,
                       "severity": 4,
                        "message": 5
                    }
                },
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            }
        ]
    }
    

然后重启vscode,就可以用gdb调试了。


参考资料

  1. https://ywnz.com/linuxjc/4077.html
  2. https://zhuanlan.zhihu.com/p/66921426
  3. https://jingyan.baidu.com/article/a501d80c65806dec630f5e91.html
  4. https://blog.csdn.net/jinjianghai/article/details/103251417
  5. https://jingyan.baidu.com/article/359911f581c1a457fe030636.html

相关文章

网友评论

      本文标题:vscode 配置C/C++开发环境

      本文链接:https://www.haomeiwen.com/subject/jgusuhtx.html