Skip to content

Instantly share code, notes, and snippets.

@jbking
Created February 1, 2011 10:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbking/805665 to your computer and use it in GitHub Desktop.
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.
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