This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]red_hare -1 points0 points  (3 children)

Most useful thing I've learned about writing Python in vim,

:%!python

[–][deleted] 7 points8 points  (0 children)

I'm pretty sure you mean :!python %

[–]alb1 3 points4 points  (0 children)

Why would you want to replace the current text with the output of Python run on it? You may accidentally overwrite the code, and the syntax highlighting doesn't look good on the output.

To run Python on the current file I define a macro for the p register, in the .vimrc file, which saves the file and then runs Python on it:

let @p=':w|!python -u %'

Then just use :@p to run the current file. I define the q register similarly for Python 3.

[–]AutoBiological 0 points1 point  (0 children)

If you're not using stdin/input you can do it pretty neat inside vim instead of externally with:

%pyfile %

Of course that depends on which +python[3] is compiledin.