How to Debug Python code in Vim
Many times we find ourselves in a remote server trying to fix a complex python issue. Would it be great if we had a cool debugger to help as fix the issue asap to save the day. With Vim which can be found on most servers and python we can do the job.
1) Install pudb
sudo pip install pudb
Make sure $HOME/.config/pudb has correct permissions to wrtie and read in my ubuntu directory
2) Onced installed add the following to your .vimrc file:
let mapleader = ","
In my case leader key is, change this to whatever you want:
nmap <leader>d :term python -m pudb % <cr>
3) Close up save and open a python file you want to debug with vim:
To add a breakpoint simply add
import pudb; pudb.set_trace()
press "n" to go to next line and watch the debugger display your variables. To go back to vim code simple ctrl+w+down arrow key
#!/usr/bin/python3
print("Hello")
a=1
b=2
c=3
import pudb; pudb.set_trace()
Sample code:
¡Happy debugging!



















