1. 安裝vimspector
使用vimspector 插件
vimrc文件中添加插件并安裝
Plug 'puremourning/vimspector'
2. 安裝vimspector C++調(diào)試適配器
打開(kāi)vim
:VimspectorInstall --enable-c
會(huì)在 ~/.vim/plugged/vimspector/gadgets/linux/ 目錄安裝vscode-cpptools
3. 添加.vimspector.json模板
vim ~/.vim/.vimspectorjson/cpp.json
{
"configurations": {
"cpp:launch": {
"adapter": "vscode-cpptools",
"configuration": {
"name": "cpp:launch",
"stopAtEntry": true,
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/a.out",
"args": [],
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"breakpointers": {
"exception": {
"cpp_throw": "Y",
"cpp_catch": "N"
}
}
}
},
"cpp:attach": {
"adapter": "vscode-cpptools",
"configuration": {
"name": "cpp:attach",
"stopAtEntry": true,
"type": "cppdbg",
"request": "attach",
"program": "${workspaceRoot}/a.out",
"MIMode": "gdb",
"breakpointers": {
"exception": {
"cpp_throw": "Y",
"cpp_catch": "N"
}
}
}
}
}
}
4. 配置快速生成模板快捷鍵
vim ~/.vimrc
// 1. 安裝fzf
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
// 2. 添加快捷鍵<leader>db快速生成.vimspector.json
"vimspector
let g:vimspector_enable_mappings = 'VISUAL_STUDIO'
"let g:vimspector_base_dir=expand('~/.vim/.vimspectorjson')
function! s:read_template_into_buffer(template)
" has to be a function to avoid the extra space fzf#run insers otherwise
execute '0r ~/.vim/.vimspectorjson/'.a:template
endfunction
command! -bang -nargs=* LoadVimSpectorJsonTemplate call fzf#run({
\ 'source': 'ls -1 ~/.vim/.vimspectorjson',
\ 'down': 20,
\ 'sink': function('<sid>read_template_into_buffer')
\ })
noremap <leader>db :tabe .vimspector.json<CR>:LoadVimSpectorJsonTemplate<CR>
sign define vimspectorBP text=? texthl=Normal
sign define vimspectorBPDisabled text=? texthl=Normal
"sign define vimspectorPC text=? texthl=SpellBad
5. 實(shí)例
5.1 添加調(diào)試模板
在項(xiàng)目中添加.vimspector.json配置
打開(kāi)vim矛绘, 在normal模式下輸入快捷鍵<leader>db跌榔,選擇cpp.json顯示如下:
修改配置文件
5.2 按F5啟動(dòng)調(diào)試
5.3 調(diào)試快捷鍵
可以直接是作者的GitHub(https://github.com/puremourning/vimspector)上查看文檔,我用的是vscode風(fēng)格的快捷鍵