14

This is what I need - have a key that will create ctags of my python site-packages.

I have this command, that will print the site-packages path:

!python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

This is how I to the key mapping:

map <F11> :!ctags -R -f ./tags *site-packages-path-goes-here*<CR>

How do I plug in the result of one command into the key binding statement?

The reason I want to get the site-packages path at the runtime is that I use virtualenv intensively. As the result the desired path changes all the time.

4

3 回答 3

9

这应该有效:

map <F11> :exe '!ctags -R -f ./tags ' . shellescape(system('python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"'))<CR>

但是如果你的 shell 支持它,为什么不直接:

map <F11> :!ctags -R -f ./tags `python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()`<CR>
于 2010-07-04T22:49:37.693 回答
3

我知道上面给出的答案有效,但我想提出一个替代方案

map <F11> :!ctags -R -f ./tags $VIRTUAL_ENV/lib/python2.7/site-packages<CR>
于 2012-10-10T06:16:44.387 回答
0

我在使用这样的命令时遇到了一些问题(取自这篇文章):

ctags -R --fields=+l --languages=python --python-kinds=-iv -f ./tags $(python -c "import os, sys; print(' '.join('{}'.format(d) for d in sys.path if os.path.isdir(d)))")

在使用 python 3.6 激活的 virtualenv 中,我的系统决定在使用上面的命令时使用 system-default python 2.7。

所以我想向您展示我的解决方案:

python -c \"import os, sys; print(' '.join('{}'.format(d) for d in sys.path if os.path.isdir(d)) + ' ./')\" | xargs /usr/bin/ctags -R

于 2017-09-28T10:29:14.067 回答