Created
February 1, 2011 10:16
-
-
Save jbking/805665 to your computer and use it in GitHub Desktop.
add your virtualenv's site-packages to vim python. then you can use vim python with modules of the site-packages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! Workon(name) | |
" Get virtualenv's site-packages directory. | |
let b:virtualenv_sitepackages_dir = system('workon ' . a:name . '; cdsitepackages; echo -n $PWD') | |
python << EOM | |
import vim | |
import sys | |
virtualenv_sitepackages_dir = vim.eval('b:virtualenv_sitepackages_dir') | |
if virtualenv_sitepackages_dir not in sys.path: | |
# Because a python plug-in might have custom version module, | |
# we put the path on tail. | |
sys.path.append(virtualenv_sitepackages_dir) | |
EOM | |
endfunction | |
function! Deactivate() | |
if exists('b:virtualenv_sitepackages_dir') | |
python << EOM | |
import vim | |
import sys | |
virtualenv_sitepackages_dir = vim.eval('b:virtualenv_sitepackages_dir') | |
if virtualenv_sitepackages_dir in sys.path: | |
sys.path.remove(virtualenv_sitepackages_dir) | |
EOM | |
unlet b:virtualenv_sitepackages_dir | |
else | |
echoerr "You aren't in a virtualenv" | |
endif | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment