Vim Debug & Test
1.24
Debug
Vimspector
Install
Plugin 'puremourning/vimspector'
Dependencies
Vim or Neovim with Python3.10 or later. Check :echo has('python3')
# neovim example
python3 -m pip install --user --upgrade pynvim
Add adapters for node and python
./install_gadget.py --force-enable-node --enable-python
Add configuration
Nodejs and Python example. Press F5 on *.js
or *.py
files.
.vimspector.json
{
"$schema": "https://clcode.net/assets/vimspector.schema.json",
"adapters": {},
"configurations": {
"Node": {
"adapter": "js-debug",
"filetypes": [ "javascript" ],
"default": true,
"configuration": {
"request": "launch",
"stopOnEntry": false,
"console": "integratedTerminal",
"program": "${file}",
"cwd": "${workspaceRoot}"
},
"breakpoints": {
"exception": {
"all": "",
"uncaught": ""
}
}
},
"Python": {
"adapter": "debugpy",
"filetypes": [ "python" ],
"default": true,
"configuration": {
"request": "launch",
"program": "${file}",
"stopOnEntry": false,
"cwd": "${workspaceRoot}"
},
"breakpoints": {
"exception": {
"raised": "N",
"uncaught": "",
"userUnhandled": ""
}
}
}
}
}
Mappings
Human Mode
let g:vimspector_enable_mappings = 'HUMAN'
Key | Mapping | Function |
---|---|---|
F5 | <Plug>VimspectorContinue | When debugging, continue. Otherwise start debugging. |
F3 | <Plug>VimspectorStop | Stop debugging. |
F4 | <Plug>VimspectorRestart | Restart debugging with the same configuration. |
F6 | <Plug>VimspectorPause | Pause debuggee. |
F9 | <Plug>VimspectorToggleBreakpoint | Toggle line breakpoint on the current line. |
<leader>F9 | <Plug>VimspectorToggleConditionalBreakpoint | Toggle conditional line breakpoint or logpoint on the current line. |
F8 | <Plug>VimspectorAddFunctionBreakpoint | Add a function breakpoint for the expression under cursor |
<leader>F8 | <Plug>VimspectorRunToCursor | Run to Cursor |
F10 | <Plug>VimspectorStepOver | Step Over |
F11 | <Plug>VimspectorStepInto | Step Into |
F12 | <Plug>VimspectorStepOut | Step out of current function scope |
In addition, I recommend adding a mapping to <Plug>VimspectorBalloonEval
, in
normal and visual modes, for example:
" mnemonic 'di' = 'debug inspect' (pick your own, if you prefer!)
" for normal mode - the word under the cursor
nmap <Leader>di <Plug>VimspectorBalloonEval
" for visual mode, the visually selected text
xmap <Leader>di <Plug>VimspectorBalloonEval
You may also wish to add mappings for navigating up/down the stack, toggling the breakpoints window, and showing disassembly, for example:
nmap <LocalLeader><F11> <Plug>VimspectorUpFrame
nmap <LocalLeader><F12> <Plug>VimspectorDownFrame
nmap <LocalLeader>B <Plug>VimspectorBreakpoints
nmap <LocalLeader>D <Plug>VimspectorDisassemble
📖