Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send line number from Python traceback into vim?

I can parse out the paths to the files of a Python traceback, and I can then send those on to Vim using -p on the command line, so that they are opened one file per tab. So I end up with a command like, for example

vim -p main.py module.py another.py

That opens each file in a new tab, but I would like them opened in a new tab, at the correct line number. So I have tried variations like

vim -p main.py +10 module.py +20 another.py +30

But I cannot seem to get Vim to respect the line numbers I send in on command line - it always just takes the last line number and applies it to first tab. So the example left me in main.py at line 30. Trying variations like

vim -p main.py+10 module.py+20 another.py+30
vim -p main.py\ +10 "module.py +20" another.py@30

all just ended up with bad filenames.

Answers at the level of Python, or Bash command line, or within Vim script, or Vim-Python would all be welcome. Or, indeed, entirely different approaches

(The tracebacks could come from anywhere, and are not necessarily controllable by me. The one that started me off today was just a set of lines in a log from a server.)

like image 651
jalanb Avatar asked Jul 04 '12 17:07

jalanb


1 Answers

Try vim plugin: file_line:

vim -p new main.py:10 module.py:20 another.py:30

Known Issue: the first filename should not have a lineno. (I'm trying to figure out WHY...)

like image 157
kev Avatar answered Oct 22 '22 10:10

kev