Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I have tried Googling but I couldn't find anything relevant.

Is it possible to program in Python on VIM and do something like


to have Python execute the code?

Last time I tried that, it just opened up Python in the terminal.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Save the current buffer with :w, then :!/usr/bin/env python %.

share|improve this answer
Then that will execute the program or the command in the shell whichever I have written? – dustin Mar 27 '13 at 15:06
It will run the file you are currently editing (presumably a Python program) in Python. Give it a try. – tgies Mar 27 '13 at 18:15
I just tried it. It executed and then said hit enter to return. So everything went through but python didn't come up and show anything. – dustin Mar 27 '13 at 18:51
now I am receiving invalid syntax errors for something I ran yesterday with no problems. Is there anything that needs to be setup in /.vimrc for this to work? – dustin Mar 27 '13 at 19:17
No. If you are receiving invalid syntax errors, it's probably because you have invalid Python syntax. Nothing about how vim is configured will impact that. – tgies Mar 27 '13 at 19:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.