Setting up Neovim for Rust Debugging — termdebug and vimspector


For Vim/Neovim, setting up Debug Adapter Protocol (DAP) for your preferred languages might not be so straight forward. Plugins like vimspector and nvim-dap which support DAP are available but the setup is not as easy compared to Visual Studio Code.


I will be using cargo to manage the project and packages. To ensure the debugging symbols are generated correctly, add these lines in cargo.toml. If you are using a workspace, put them in the root cargo.toml.

opt-level = 0
debug = true
opt-level = 3
debug = false


termdebug is available starting Vim 8.1 and ported to Neovim. To use termdebug for Rust debugging, from Neovim

:packadd termdebug
:let termdebugger="rust-gdb"
(gdb) set startup-with-shell off
Starting program: /xx/xxx
Unable to find Mach task port for process-id 48815: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))
termdebug screen in Neovim
(gdb) file target/debug/deps/myapp1-a90fa71044df8bea
Neovim termdebug Debugging

Side Note

gdb also provides a terminal based user interface for debugging. Just run gdb — tui, add the binary using file command and you can start debugging.

# gdb --tui
gdb tui


This is a vim plugin that you need to install. I use vim-plug to install it

Plug 'puremourning/vimspector'
"adapters": {
"lldb-vscode": {
"variables": {
"LLVM": {
"shell": "brew --prefix llvm"
"attach": {
"pidProperty": "pid",
"pidSelect": "none"
"command": [
"env": {
"name": "lldb"
let g:vimspector_enable_mappings = 'HUMAN'nmap <leader>dd :call vimspector#Launch()<CR>
nmap <leader>dx :VimspectorReset<CR>
nmap <leader>de :VimspectorEval
nmap <leader>dw :VimspectorWatch
nmap <leader>do :VimspectorShowOutput
let g:vimspector_install_gadgets = [ 'debugpy', 'vscode-go', 'CodeLLDB' ]
"configurations": {
"launch": {
"adapter": "CodeLLDB",
"configuration": {
"request": "launch",
"program": "${workspaceRoot}/target/debug/myapp1"
Neovim vimspector Debugging

Programmer and occasional blogger.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store