I've seen similar questions asked before here and here, however they are 4 years old and did not yield answers that matched my requirements.
If I type Python code into Vim, for example:
os.path.join('my', 'path')
resp = requests.get('http://example.com')
HttpResponse('success')
Assuming that I had the third-party modules 'requests' and 'django' in my site-packages folder, is there any Vim plugin -- which does not use the Rope library -- that could automatically add the relevant import statements to the Python file (both for built-in & third-party modules, using either import
or from
as needed), like this:
import os
import requests
from django.http import HttpResponse
While I would traditionally use the venerable Rope package, I have been replacing Rope functions with modern alternatives to avoid the overhead of the .ropeproject folder. However, I haven't found a Vim alternative yet for auto-import.
echo .ropeproject/ >>.git/info/exclude
can cure all your problems, cannot it? – Bret