sponsor Vim development Vim logo Vim Book Ad

python-imports.vim : Scripted insertion of import statements

 script karma  Rating 1/5, Downloaded by 1102  Comments, bugs, improvements  Vim wiki

created by
Phillip Berndt
 
script type
ftplugin
 
description
This plugin automates the insertion of import statements at the top of a python script. It contains a function capable of adding import statements at the top of the file. This function is mapped to <C-f>. So you can for example type "sys.exit<C-f>" and the plugin will append "import sys" above the other import statements at the top of the file, unless sys already was imported. The script tries to maintain the import statements in order.

If you define
let g:PythonAutoAddImports = 1
in your vimrc, this script will additionally hook into the period key, such that for common modules,
imports are added as you type: Typing
if len(sys.argv) == 0:
into an empty file will leave you with
import sys
if len(sys.argv) == 0:
then.

This plugin is in its early stages. Also, it is my first vim plugin, so do not expect everything to run smoothly yet. I maintain this script an vim repo at github:

https://github.com/phillipberndt/python-imports.vim
 
install details
Copy python.vim into your ~/.vim/ftplugin folder. If you use Pathogen, create a directory ~/.vim/bundle/vim-python-imports/ftplugin and copy it there.
 

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.vim 0.2 2012-11-02 7.0 Phillip Berndt Various bug fixes
python.vim 1.0 2012-04-07 7.0 Phillip Berndt Initial upload
ip used for rating: 18.191.211.66

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