3

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.

3 Answers 3

5

The real answer (the others were close)

Do a visual selection then

:'<,'>!python -

(quickest way: Vj!python -Enter)

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

thanks, but this implies saving the file, I would like to know if it is possible to do this with just part of the file
the technique used in this question might help - stackoverflow.com/questions/230266/… ?
1

Try:

:w !python -

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.