Skip to main content

🐞 Debugging Extra

Debug C and C++ programs inside Neovim with breakpoints, stepping and variable inspection, using nvim-dap.

Enabling​

Included in the 42 extra. To enable it on its own, select dap in :FtVimExtras or add:

{ import = "ftvim.plugins.extras.dap" },

Requirements​

  • Linux: gdb 14 or newer (it speaks the debug adapter protocol natively)
  • macOS / no gdb: codelldb, installed automatically with Mason when gdb is not found

:checkhealth ftvim shows which debugger is used.

tip

Compile with -g to get breakpoints and variable names. For example, add it to CFLAGS in your Makefile while debugging (and remove it before submitting).

Usage​

  1. Build your program with -g
  2. Put the cursor on a line and press <leader>db to set a breakpoint
  3. Press <F5> (or <leader>dc). The program defaults to the Makefile's NAME, and you are asked for its arguments
  4. The debugger UI opens with variables, the call stack and breakpoints. Step with <leader>do / <leader>di / <leader>dO

Variable values are also shown inline, next to your code.

Keymaps​

KeymapDescription
<F5> / <leader>dcRun / Continue
<leader>dbToggle breakpoint
<leader>dBConditional breakpoint
<leader>dCRun to cursor
<leader>doStep over
<leader>diStep into
<leader>dOStep out
<leader>dlRun last
<leader>drToggle REPL
<leader>dtTerminate
<leader>duToggle debugger UI
<leader>deEvaluate expression (normal and visual mode)

Included Plugins​

PluginDescription
nvim-dapDebug Adapter Protocol client
nvim-dap-uiDebugger UI
nvim-dap-virtual-textInline variable values