Ⅰ. 插件描述
Sort and highlight Python imports in VimⅡ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'tweekmonster/impsort-vim'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'tweekmonster/impsort-vim'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'tweekmonster/impsort-vim'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/tweekmonster/impsort.vim
Ⅳ. 文档说明
# impsort.vim
Vim utility for sorting and highlighting Python imports.

Installation
Any modern plugin manager will work. If you are installing manually, you will
have to run git submodule update --init since [Jedi][] is included as a
submodule.
Usage
:ImpSort[!]The :ImpSort command accepts a range and can be used with visual selections.
Using :Impsort! (with bang) will separate from ... import groups with a
blank line.
You could also have it sort on save:
autocmd BufWritePre *.py ImpSort!Or use a keymap:
nnoremap <leader>is :<c-u>ImpSort!<cr>The sorting method is configurable. Be sure to read :h impsort!
There is another command :ImpSortAuto which will automatically sort imports
on InsertLeave. Definitely read :h impsort if this
interests you.
Highlighting
By default, imported objects will be highlighted. If your version of Vim is
capable of asynchronous calls (Neovim and Vim 8), the highlighting will
distinguish imported classes and functions. You can read about customizing the
colors in the documentation.
Rationale
I wanted to be able to keep my import lines organized, but didn't want to spend
the time sorting them by hand. Using this plugin, you can add a new import and
let the sort do its thing.
I also wanted something more forgiving than [isort][]. This plugin will not
move imports out of their original placement in the script. For example:
import sys
import os
sys.path.insert(0, 'special/path')
import specialWith isort:
import os
import sys
import special
sys.path.insert(0, 'special/path')With impsort.vim:
import os
import sys
sys.path.insert(0, 'special/path')
import special