Here’s a useful command-mode mapping for Python development:
" ~/.vim/ftplugin/python.vim function! VirtualEnvSitePackagesFolder() " Try a few candidate Pythons to see which this virtualenv uses. for python in ["python3.7", "python3.8", "python3.9"] let candidate = $VIRTUAL_ENV . "/lib/" . python if isdirectory(candidate) return candidate . "/site-packages/" endif endfor return "" endfunction cnoremap %v <C-R>=VirtualEnvSitePackagesFolder()<cr>
%v will expand to the path of your virtualenv’s
site-packages folder in, which makes it easy to quickly open a third-party
For example, you type:
and it expands to:
from which it’s easy to open the third-party module you’re interested in.