I use vim for coding and for python coding in particular. Often I want to execute the current buffer with python interpreter. (for example to run unittests), usually I do this with :!python % <Enter>
This scenatio will work works fine with global python, but I want to run virtualenv python instead. How do I enable virtualenv within vim? Is it possible to switch virtualenv on the runtime?
I’m using macvim
Here’s what I use (sorry the highlighting is screwy).
Note that you need to have MacVim compiled against the Python you are using for the virtualenv, e.g. if you downloaded Python 2.7 from Python.org you should recompile MacVim using
--with-python-config-dir=/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/configas an argument to./configure.Hope that helps!
EDIT: Just one note of attribution: A lot of the detective work that went into writing this little ditty was done by this blogger, and he deserves some of the credit.