vimtricks.wiki Concise Vim tricks, one at a time.

How do I launch a GDB session in Vim with the built-in termdebug plugin?

Answer

:packadd termdebug | Termdebug

Explanation

For quick debugging without leaving Vim, the built-in termdebug plugin wires a GDB session directly into your editing workflow. Instead of context-switching to a separate terminal debugger, you can set breakpoints, step, and inspect state while staying inside your current layout.

This is most useful when you need short debug loops during active editing and want source navigation plus debugger control in one place.

How it works

  • :packadd termdebug loads the runtime plugin on demand
  • :Termdebug starts a debugger session and opens the required terminal/split windows
  • Breakpoints and stepping commands become available through the plugin integration

Example

:packadd termdebug | Termdebug

From there, run standard debugging actions in the provided windows (set breakpoints, continue, step), while keeping your source buffer active for edits.

Tips

  • Add program arguments after :Termdebug when needed
  • Because this is loaded on demand, startup stays fast when you are not debugging
  • If you debug often, map a key to :packadd termdebug | Termdebug for one-shot launch

Next

How do I keep a split at a fixed width when opening and closing other windows?