[Tutor] Re: Using Python with VI

Abel Daniel abli at freemail.hu
Tue Feb 3 15:52:27 EST 2004


"Barry Smithers" writes:

> I'm having difficulty with a program call from inside of VI.  What I
> basically need to do is get the line numbers input in the ex command.  Or
> maybe even get the text on those lines to go into a list.  For example the
> ex command ":20,21!xxx.py" would run xxx.py as a whole, but I need the data
> currently on lines 20 and 21 for modification.

This ex command expects the program you run (xxx.py) to be a filter: it should
read on stdin and write to stdout. Something like this:

---
import sys
l=sys.stdin.readlines() # this l will be the list you need
print "l:", l # print writes to stdout by default. Or you can use 
              # sys.stdout.write()
              # (and .flush(), and .close(), just to be safe)
---

I don't know how you could pass the _line_numbers_ (instead of the contents
of the lines).

-- 
Abel Daniel



More information about the Tutor mailing list