skeept
skeept

Reputation: 12413

replace output of lines through external command

Suppose I have several lines of python code:

for i in range(10):
    print "item {}".format(i)

is there a way I can get the output of the lines directly in vim without having to copy the text into the interpreter and copy the output back?

The lines are usually just a part of the file, not the hole file.

Upvotes: 3

Views: 167

Answers (3)

sehe
sehe

Reputation: 392833

The real answer (the others were close)

Do a visual selection then

:'<,'>!python -

(quickest way: Vj!python -Enter)

Upvotes: 5

Michael Wayne
Michael Wayne

Reputation: 176

Try:

:w !python -

That should execute the entire file by itself, or just a selection if you have something highlighted.

Upvotes: 1

arunkumar
arunkumar

Reputation: 34043

You should be able to do :read !python myscript.py and get the output pasted into your current buffer. This vim wikia entry provides more info.

Upvotes: 1

Related Questions