How do I launch GDB inside Vim using the built-in termdebug plugin without preloading it?
Answer
:packadd termdebug | Termdebug ./a.out
Explanation
If you only debug occasionally, loading termdebug on demand keeps startup lean while still giving you an in-editor GDB workflow. This command loads the optional runtime plugin and immediately starts a debug session for your binary. It is a practical middle ground between always-on debugging plugins and context switching to an external terminal.
How it works
:packadd termdebugloads Vim's optionaltermdebugpackage from the runtime packages directory|chains the next Ex command in the same line:Termdebug ./a.outstarts GDB for./a.outand opens the debugging layout- You get source navigation, breakpoints, and terminal-driven debugger interaction from inside Vim
Example
After compiling your program:
:packadd termdebug | Termdebug ./a.out
Set breakpoints and run:
:Break
:Run
As execution stops, Vim jumps to relevant source lines while GDB output remains available in terminal windows.
Tips
- Keep this as a command-line abbreviation or mapping if you debug frequently
- Use
:help terminal-debugfor the full command set (:Break,:Step,:Over, etc.) - For projects with arguments, pass them through GDB commands after launch