Hassek
Hassek

Reputation: 8995

find virtualenv current package directory for vim

I want to be able to reach source code from my virtualenv library via ctags but to be able to do this I need to know which virtualenv is currently active, so for example, I have this code in my .vimrc which appends django to my ctags index:

nnoremap <F7> :!ctags -R --python-kinds=-i -a ~/.virtualenvs/MYPROJECT/lib/python2.7/site-packages/django/*<CR>

Instead of hardcoding the path I want it to do something like:

nnoremap <F7> :!ctags -R --python-kinds=-i -a CURRENT_PROJECT_PACKAGES_PATH/django/*

so I can index packages from the current project I am working on.

Upvotes: 1

Views: 766

Answers (2)

Chuan Yeong
Chuan Yeong

Reputation: 3639

You could use $VIRTUAL_ENV to get to your library, so it'd be something like this

nnoremap <F7> :!ctags -R --python-kinds=-i -a $VIRTUAL_ENV/lib/python2.7/site-packages/django/*

Upvotes: 2

Conner
Conner

Reputation: 31060

Use a variable like let g:current_proj = "~/.virtualenvs/MYPROJECT/lib/python2.7/site-packages/" then read it in with an exe:

nnoremap <F7> :exe "!ctags -R --python-kinds=-i -a " . g:current_proj . "django/*"<cr>

or you can just directly use an environment variable:

nnoremap <F7> :exe "!ctags -R --python-kinds=-i -a " . $CURRENT_PROJECT_PACKAGES . "django/*"<cr>

Upvotes: 0

Related Questions