开发环境与工具

七月 18, 2025 [tools] #vscode #vim #emacs #asan #debug #editor

开发环境与工具

VSCode

核心插件

插件用途
vscodevim.vimVim 模拟
llvm-vs-code-extensions.vscode-clangdC++ LSP
rust-lang.rust-analyzerRust LSP
ms-vscode.cmake-toolsCMake 集成
mhutchie.git-graphGit 图形化
GitHub.copilotAI 补全
ms-vscode-remote.remote-sshSSH 远程开发
shd101wyy.markdown-preview-enhancedMarkdown 预览
bierner.markdown-mermaidMermaid 图表

Ctrl+P 快捷操作

常用快捷键

快捷键功能
Ctrl+Shift+T重开刚关闭的页面
Ctrl+Shift+F全局文本搜索
Ctrl+J切换终端
F2重命名符号
F12跳转到定义
Ctrl+Alt+R重新加载窗口
Ctrl+Alt+左/右移动标签到其他组
Ctrl+B切换侧边栏

VSCode 中配置 Vim/Emacs 快捷键

安装 vscodevim.vim 插件后,在 keybindings.json 中禁用冲突的快捷键:

[
    {
        "key": "ctrl+a",
        "command": "-extension.vim_ctrl+a",
        "when": "editorTextFocus && vim.active"
    },
    {
        "key": "ctrl+e",
        "command": "-extension.vim_ctrl+e",
        "when": "editorTextFocus && vim.active"
    }
]

调试配置(launch.json)

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gdb attach",
            "type": "lldb",
            "request": "attach",
            "pid": "${command:pickProcess}",
            "program": "${workspaceFolder}/target/debug/app",
            "setupCommands": [
                { "text": "-gdb-set follow-fork-mode child" }
            ]
        },
        {
            "name": "Python: 当前文件",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

Sudo 调试:debuggerPath 指向包装脚本 sudo-gdb.sh

#!/bin/bash
sudo rust-gdb $@

任务配置(tasks.json)

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cargo",
            "command": "build",
            "args": ["--bin", "http-proxy"],
            "problemMatcher": ["$rustc"],
            "group": "build",
            "label": "rust: cargo build http"
        }
    ]
}

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": ["${workspaceFolder}/**"],
            "compilerPath": "/root/.local/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++14",
            "intelliSenseMode": "linux-clang-x64"
        }
    ],
    "version": 4
}

Vim / Emacs

Vim 常用操作

" 临时 root 写权限
:w !sudo tee %

" 粘贴模式(避免自动缩进错乱)
:set paste

" 禁用鼠标
:set mouse=

Emacs

;; 以 root 保存
C-x C-w /sudo::/etc/apt/source.list

;; Magit diff 细化
(setq magit-diff-refine-hunk t)

LSP Server

pip3 install cmake-language-server

ASan(Address Sanitizer)

检测的错误类型

工作原理

通过影子内存(1:8 压缩比,8 字节对齐)记录主内存可用性。对象前后布置红区(red zone)检测越界,free 后立即投毒(poisoning)。

使用

gcc -fsanitize=address -g main.c -o main

Flyway Checksum 修复

UPDATE flyway_schema_history SET checksum = -1923952184 WHERE version = 17;