10

Is it possible to debug Python scripts line by line using :Termdebug?

:help termdebug-customizing says, that you need a debugger that is "fully compatible with gdb". Is there a debugger for Python that is compatible (using the GDB/MI interface)?

Or are there other alternatives?

6
  • 1
    I don't have the experience to answer you but the plugin python-mode has a feature which allows you to use breakpoints in python see here they also mention the following debuggers: pdb, ipdb, pudb. – statox Nov 15 '18 at 9:35
  • @Jakube did you figure out how to do this using Vim's :Termdebug? I am also very interested in how this works without using a bunch of plugins out the gate. – FilBot3 Oct 22 '20 at 21:17
  • 1
    @FilBot3 From what I was able to collect, all the Python debuggers are incompatible with the GDB interfaces, so you can't use them with :Termdebug. You can debug Python with GDB itself, however then you are working on the C-level of the Python application. There is one way that allows you to work with the actual Python code in GDB (see this talk: youtube.com/watch?v=rB9rPdMRxIA), however I haven't tried that yet, so I can't tell from experience. – Jakube Oct 23 '20 at 10:33
  • I sounds a little annoying, since you need to use the py- prefix everywhere (py-up instead of up), but in general that approach should work also nicely with :Termdebug. – Jakube Oct 23 '20 at 10:33
  • Posted a similar question up on Reddit too. reddit.com/r/vim/comments/jg91dt/… – FilBot3 Oct 23 '20 at 19:58
9

There are alternatives.

Plain ol' pdb can be integrated into vim with

(My own favourite) pudb can be integrated with

And the popular ipdb can be integrated with

2
  • 2
    vimpdb seems to support python 2 only github.com/gotcha/vimpdb#requirements – baxx Aug 1 '20 at 11:07
  • 1
    This also doesn't answer the OP's question of how to use the built-in Vim functionality. From what I see these plugins all use something that is outside of the Vim Termdebug native funcionality – FilBot3 Oct 22 '20 at 21:14
6

For me vimspector looks amazing, and has out-of-the-box Python support.

1
  • Currently, it is really the best one. Based on VS-Code debugger. – eyal karni Dec 2 '20 at 22:44
1

You could simply make shortcuts on python files that imports pdb and add a pdb.set_trace() etc.

But I use PUDB (that is the same, but with syntax highlight and all good graphical stuff) with the command :term python -m pudb %. It basically opens a new split window with the debug, the call stack...

I found that simple and convenient (and I remapped it on <f6>)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.