Ⅰ. 插件描述
Text objects for Python.Ⅱ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'bps/vim-textobj-python'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'bps/vim-textobj-python'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'bps/vim-textobj-python'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/bps/vim-textobj-python
Ⅳ. 文档说明
# vim-textobj-python
This is a Vim plugin to provide text objects for Python functions and classes.
It provides the following objects:
af: a functionif: inner functionac: a classic: inner class
It also provides a few motions in normal and operator-pending mode:
[pf/]pf: move to next/previous function[pc/]pc: move to next/previous class
Installation
It requires kana's vim-textobj-user,
version 0.4.0 or later. I recommend installing both vim-textobj-user andvim-textobj-python with pathogen.
Configuration
If you'd like to change the default mappings (whether for personal preference
or to avoid conflicts with other plugins, define a global variableg:textobj_python_no_default_key_mappings before this plugin is loaded
(typically in your vimrc):
let g:textobj_python_no_default_key_mappings = 1
Then define the mappings with the helper function:
call textobj#user#map('python', {
\ 'class': {
\ 'select-a': '<buffer>ac',
\ 'select-i': '<buffer>ic',
\ 'move-n': '<buffer>]pc',
\ 'move-p': '<buffer>[pc',
\ },
\ 'function': {
\ 'select-a': '<buffer>af',
\ 'select-i': '<buffer>if',
\ 'move-n': '<buffer>]pf',
\ 'move-p': '<buffer>[pf',
\ }
\ })
You can also use :TextobjPythonDefaultKeyMappings to redefine the default
key mappings. This command doesn't override existing mappings, unless [!] is
given.
You can also manually define the mappings as follows:
xmap aF <Plug>(textobj-python-function-a)
omap aF <Plug>(textobj-python-function-a)
xmap iF <Plug>(textobj-python-function-i)
omap iF <Plug>(textobj-python-function-i)
Unit tests
There are a few unit tests available in test/. They're written using
Vader.
TODO
- Skip improperly-indented comment lines
- Handle inner function on multiline def one-liner:
def foo(bar,
baz): pass