Skip to content

Instantly share code, notes, and snippets.

@rmax
Created June 6, 2010 23:07
Show Gist options
  • Save rmax/428009 to your computer and use it in GitHub Desktop.
Save rmax/428009 to your computer and use it in GitHub Desktop.
function! EnableVirtualEnv()
python << EOF
import vim
import os
import sys
if 'VIRTUAL_ENV' in os.environ:
vim.command('let g:virtualenv_found = 1')
# enable virtualenv environment within vimruntime
activate_this = os.path.join(os.environ['VIRTUAL_ENV'], 'bin/activate_this.py')
if os.path.isfile(activate_this):
execfile(activate_this, dict(__file__=activate_this))
vim.command('let g:virtualenv_enabled = 1')
else:
vim.command('let g:virtualenv_enabled = 0')
# allow to have custom vimrc per virtualenv
vimrc = os.path.join(os.environ['VIRTUAL_ENV'], '.vimrc')
if os.path.isfile(vimrc):
vim.command('source %s' % vimrc)
vim.command('let g:virtualenv_vimrc = 1')
else:
vim.command('let g:virtualenv_vimrc = 0')
else:
vim.command('let g:virtualenv_found = 0')
EOF
endfunction
call EnableVirtualEnv()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment