Executing Python with Gvim


  • open gVim.
  • then using the File Menu and MenuItem Open to open a file pi.py which has the following tiny script:

enter image description here

How do I execute this code using gVim?


If I use either :! python pi.py or :w !python - then I get the following:

enter image description here

2/2/2014 7:50:05 AM

Accepted Answer

You don't need to save the file, you can run the current buffer as stdin to a command such as python by typing:

:w !python -

(The hyphen at the end probably isn't necessary, python will generally use stdin by default)

edit: seeing as you are new to vim, note that this will not save the file, it will just run it. You will probably want to learn how to save your file.

5/5/2013 5:42:21 PM

If you have python support compiled into vim you can use :pyfile % to run the current file. (python 2.7)

If you have python 3 support use :py3file % instead

pyfile help

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow