Say I have a python script with a runtime error:
$ cat example.py
#! /usr/bin/env python3
a = 1/0
which gives:
$ python3 example.py
Traceback (most recent call last):
File "example.py", line 3, in <module>
a = 1/0
ZeroDivisionError: division by zero
I want Vim to jump to the problematic line of that file (line 3 in this case). I know Vim can do this because it works just fine for catching errors at compile time in C with gcc
using :make
and the quickfix
window.
Sure, I can populate Vim's quickfix window with :set makeprg=python3\ %
and then :make
, but it does not jump to the line number where the traceback points to. When I look in :copen
it just highlights the first line of the trace, and I can't jump to the relevant line number.
(I'm using Vim 7.4 on Debian jessie
in case that matters.)
My questions are:
Can I configure Vim so that it knows how to get the relevant line number from a Python traceback?
Can I modify the Python interpreter to spit out an error format that Vim already knows how to parse and get the relevant line number?
errorformat
accordingly and write a compiler plugin for Vim (see:help :compiler
and:help write-compiler-plugin
). Probably not worth the effort if you don't know exactly what you're doing and you're not enthusiastic enough to dig everything out from the docs.:Dispatch python3 %
will return the output of the current script as a quick fix window.