GDB edit
command
Opens an editor on the current line using the command:
$EDITOR +<current-line> <current-file>
The default editor
is ex
, but vim
also understands the +<current-line>
format.
When you quit the editor, you get back into gdb
.
This allows you to browse the source freely and is specially powerfull if you have ctags
integration.
This is a poor-man's built-in one way gdb to vim integration: the main missing thing is setting breakpoints from Vim.
edit
and center
edit
does not center Vim by default around the source, so I've created a Python script that does it: How to open the current file at the current line in a text editor from GDB?
Breakpoint command to clipboard helper
This vim command copies a breakpoint specifier of type:
b <file-path>:<line-number>
to the clipboard:
command! Xg :let @+ = 'b ' . expand('%:p') . ':' . line('.')
Then you can just paste that into gdb
.
This is a poor man's vim to gdb integration to ease setting breakpoints.
GDB Dashboard
https://github.com/cyrus-and/gdb-dashboard
This has nothing to do with Vim, but it is a lightweight solution that achieves a lot and might suit other Vimmers out there.
Others have mentioned GDB TUI, but I found it too broken and not powerful enough to be bearable.
So I moved instead to Python API based solutions such as GDB Dashboard.
I have described used and rationale in more detail at: gdb split view with code
Here is a screenshot of what it gives you:

See also: https://vi.stackexchange.com/questions/2046/how-can-i-integrate-gdb-with-vim
Give up and use a real IDE
With all that said, this is the best solution for most people, including myself. Most people will just gain tons of time if they are able to jump around definitions in a C++ class aware manner without selecting and installing several different plugins themselves, and that includes while step debugging stuff. As of 2020 the least worst one for me was Eclipse: https://www.slant.co/topics/1411/~best-ides-for-c-on-linux