A couple of searches later and I built my vi command:
- :%s/^$/\=printf('print "%-4d\\n";', line('.'))
What this does is replace every empty line in the code with a print of the number of the line.
e.g. if line 10 is empty then it will be be replaced with:
- print "10\n";
Otherwise it will be left as is.
Turns out the code was blocking on line 954.