Ⅰ. 插件描述
Sorts Python import statements according to PEP8 and Google guidelinesⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'public/vim-sort-python-imports'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'public/vim-sort-python-imports'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'public/vim-sort-python-imports'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/public/vim-sort-python-imports
Ⅳ. 文档说明
Auto-sort Imports
Automatically sorts your Python imports according to the PEP8 / Google style guide.
http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Imports
This is a Pathogen plugin. https://github.com/tpope/vim-pathogen
Install it and fit F9. It will sort all the imports at the top of your file.
If you have comments at the top of your file e.g. #!/usr/bin/env python
it will keep them. Unless they are interleaved with your import statements,
in which case currently it will remove them :(
Why not RopeOrganizeImports?
This plugin might seem a bit like the sort of thing Rope already does, but it isn't.
This plugin intentionally doesn't attempt to remove unused names, or to identify
imports that don't exist or are otherwise incorrect. The main reason for this is
that the changes we make to the file are smaller, and so easier to verify for the
programmer.
Our output format is also optimised to match the Google coding style guidelines.
Bugs
No attempt is currently made to detect if you are importing something other than
a package or a module.
To Do
Port this to using the Rope AST? It seems to have better fidelity than the one
in stdlib.
Alex Stapleton <alexs@prol.etari.at>