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 termdebugloads the runtime plugin on demand:Termdebugstarts 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
:Termdebugwhen 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 | Termdebugfor one-shot launch