1. vscode 在虚拟机中运行需要禁用 3D 加速。或者在 .bashrc 中添加 alias code="code --disable-gpu"
  2. settings.json 常用配置:
{
    "git.enabled": false,  // 关掉vscode git插件

    // Controls if quick suggestions should show up while typing
    "editor.quickSuggestions": {
        "other": true,
        "comments": false,
        "strings": true
    },

    "files.exclude": {  // 去除某些目录
        "*build": true,
        "*.tar.gz": true,
        "*.zip": true
    },
    "search.exclude": {  // 去除某些目录中的搜索
        "*build": true,
        "*.tar.gz": true,
        "*.zip": true
    },

    // Controls if suggestions should be accepted on 'Enter' - in addition to 'Tab'. Helps to avoid ambiguity between inserting new lines or accepting suggestions. The value 'smart' means only accept a suggestion with Enter when it makes a textual change
    "editor.acceptSuggestionOnEnter": "on",

    // Controls the delay in ms after which quick suggestions will show up.
    "editor.quickSuggestionsDelay": 10,

    // Controls if suggestions should automatically show up when typing trigger characters
    "editor.suggestOnTriggerCharacters": true,

    // Controls if pressing tab inserts the best suggestion and if tab cycles through other suggestions
    "editor.tabCompletion": "on",

    // Controls whether sorting favours words that appear close to the cursor
    "editor.suggest.localityBonus": true,

    // Controls how suggestions are pre-selected when showing the suggest list
    "editor.suggestSelection": "recentlyUsed",

    // Enable word based suggestions
    "editor.wordBasedSuggestions": true,

    "editor.parameterHints.enabled": true,
    "workbench.tree.indent": 20,  // Explorer 中目录树的宽度
    "editor.mouseWheelScrollSensitivity": 2,
    "editor.smoothScrolling": false,
    
    "editor.trimAutoWhitespace": true,
    "files.trimTrailingWhitespace": true,  // 保存时自动删除行尾的空格
    "editor.renderWhitespace": "all",  // 将空格显示为 "."

    "editor.tabSize": 4,
    "editor.insertSpaces": true,
    "editor.detectIndentation": false,
	"editor.rulers": [80],  // 显示列宽度限制为 80 个字符(竖线)

    "C_Cpp.clang_format_style": "Google",  // c++ format格式
    "C_Cpp.errorSquiggles": "Disabled",
    "C_Cpp.default.cppStandard": "c++11",
    "C_Cpp.loggingLevel": "Debug",
}
  1. 常用 debug 配置文件:
{
    "name": "(gdb)  Debug1",
    "type": "cppdbg",
    "request": "launch",
    "program": "/home/key/ws/hello.out",
    "args": ["param1", "param2"],
    "stopAtEntry": true,
    "cwd": "/home/key/ws/",
    "environment": [], //, {"name":"alloc_dealloc_mismatch", "value":"0"}],
    "externalConsole": false,
    "MIMode": "gdb",
    "setupCommands": [
        {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing", // -gdb-set follow-fork-mode child",
            "ignoreFailures": true
        },
        {
            "description": "Additional .so lib",
            "text": "set env LD_LIBRARY_PATH=/usr/local/mysql/connector-c++-8.0/lib64/",
            "ignoreFailures": true
        },
        {"text": "skip -gfi /usr/include/c++/*/*/*"},  // gdb not step into stl
        {"text": "skip -gfi /usr/include/c++/*/*"},
        {"text": "skip -gfi /usr/include/c++/*"}
    ],
    // "logging": { "engineLogging": true },
    "sourceFileMap": {
        "/opt/in/docker1":"/home/key/ws1"  // option
    }
    "logging": { "engineLogging": true }  // 输出信息到Debug Console
},
{
    "name": "(gdb) Docker Launch1",
    "type": "cppdbg",
    "request": "launch",
    "program": "/opt/hello.out",
    "cwd": "/root",
    "args": [],
    "stopAtEntry": true,
    "environment": [],
    "externalConsole": false,
    "pipeTransport": {
        "debuggerPath": "/usr/bin/gdb",
        "pipeProgram": "docker",
        "pipeArgs": ["exec", "-i", "dockerName", "bash", "-c"],  // bahs -c: read string as cmd
        "pipeCwd": "${workspaceRoot}"
    },
    // "sourceFileMap": {
    //     "/root/src":"/home/user/ws/src"  // option, 需要从docker中复制一份src到 /home/user/ws 中。
    // },
	"MIMode": "gdb",
	"setupCommands": [{
	    "description": "Enable pretty-printing for gdb",
	    "text": "-enable-pretty-printing",
	    "ignoreFailures": true
	},
	{
	    "description": "Additional libs for gdb",
	    "text": "set env LD_LIBRARY_PATH=/usr/local/mysql/connector-c++-8.0/lib64/"
	}],
	"logging": { "engineLogging": true }
}, 

注意,如果希望vscode debug 运行在docker中的程序,则需要在这样启动docker: docker run --privileged xxx (提升所有权限)或者 docker run --security-opt="seccomp=unconfined" --cap-add=SYS_PTRACE xxx (disable address space randomization + enable PTRACE).

  1. vscode Debug 查看函数返回值: step into 函数,然后再 vscode DEBUG CONSOLE 中输入 "-exec finish"
  2. vscode Debug子进程:需要提前在子进程中打上断点, 并且 break before fork && "-exec -gdb-set follow-fork-mode child"
  3. vscode Debug 查看某个地址的内存值: -exec x/4ub 0x555556e9ba10 或者 -exec x/4xb

VSCode快捷键:

https://code.visualstudio.com/shortcuts/keyboard-shortcuts-linux.pdf

按住 shift + 鼠标点选  (块选,多行选择)
Alt + Shift + 上下     (上下多光标)
Alt + Shift + 左右     (左右单词—— word 选择)
Alt + Shift + i		   (在选择行的行尾插入光标)
Alt + Shift + 鼠标拖动  (多光标快选)
Alt + 鼠标点击		(单个插入光标)
Ctrl + U					(undo 多光标操作)
Ctrl + Shift + L 		(选中所有当前所选的字符串)

Ctrl + 左右		(左右移动一个单词——word)
Ctrl + L			(单行选择——配合Ctrl+C Ctrl+V实现复制一行)
Ctrl + P			(打开文件)

以上配合 Ctrl K + Ctrl F (format当前所选),以及 Ctrl + Shift + P
Trim Trailing Whitespace
... to be continue...
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐