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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

:!iPython

to have Python execute the code?

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

share|improve this question
up vote 4 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

or even better set aw in your .vimrc, follow by

:pyf %

this will not incur you to bring up shell and hence better.

if you want you can map it and save in your .vimrc following cmd

map <F8> pyf %<CR>

hitting F8 will execute your python file

share|improve this answer
    
This is not quite the same as using /usr/bin/env python - :pyf will always use /usr/bin/pythonX (depending on python3 vs python2). – muru Jan 9 at 9:11

Your Answer

 
discard

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.