sponsor Vim development Vim logo Vim Book Ad

python_import.vim : automatically remove unused imports and clean up the rest

 script karma  Rating 8/2, Downloaded by 967  Comments, bugs, improvements  Vim wiki

created by
Jason Lunz
 
script type
ftplugin
 
description
This plugin defines a function for automatically cleaning up the imports
in a python module or program. It does two things:

- removes unused imports
- sorts and formats the remaining imports

This function is mapped to <LocalLeader>i (for "import") in two contexts.
In Normal mode, it operates on the current paragraph.
In Visual mode, it operates on the selected range.

The python 'tokenize' module is used to determine which symbols are used
in the current buffer, so the script is pretty good at identifying unused imports.

The import formatting style was chosen to work well with grep - the name of
the module and the symbols imported from it are guaranteed to always
appear on the same line.
 
install details
Just drop the file in ~/.vim/ftplugin.

vim must be compiled with +python.
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
python_import.vim 0.2 2014-01-09 7.0 Jason Lunz clean up imports ;)
python_import.vim 0.1 2007-05-04 7.0 Jason Lunz Initial upload
ip used for rating: 52.14.221.113

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github