Setting up Neovim for Rust Debugging — termdebug and vimspector

alpha2phi
4 min readDec 24, 2020

Overview

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.

In my previous article I demonstrated to you how to debug Rust code using VS Code. In this article I will show you how to debug Rust code in Neovim using termdebug (built-in plugin bundled with Vim starting 8.1) and vimspector (a vim plugin supports DAP).

cargo.toml

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.

[profile.dev]
opt-level = 0
debug = true
[profile.release]
opt-level = 3
debug = false

termdebug

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

:packadd termdebug

Alternatively you can add this line to your .vimrc or init.vim.

Then change the debugger to rust-gdb.

:let termdebugger="rust-gdb"

Start termdebug. This command also accepts the binary file to be debugged as the parameter, e.g. :Termdebug

--

--

alpha2phi

Software engineer, Data Science and ML practitioner.