vim-autosurround


Ⅰ. 插件描述

Automatically insert pairs (brackets, quotes) where they are supposed to be

Ⅱ. 基本信息

创建日期:  2015-10-11
使用用户:  5
Github星:  49
插件作者:  reconquest

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'seletskiy/vim-autosurround'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'seletskiy/vim-autosurround'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'seletskiy/vim-autosurround'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/seletskiy/vim-autosurround

Ⅳ. 文档说明

Plugin will automatically add enclosing ) (or any other) at appropriate place to be.

gif

Currently, following cases are supported:

  • adding pair after call-like construction:

    |something()        type: test( ->
    test(|something())
  • adding pair after string:

    |"blah"       type: test( ->
    test(|"blah")
  • adding pair after argument:

    something(|arg1, arg2)        type: test( ->
    something(test(|arg1), arg2)
    something(arg1, |arg2)        type: test( ->
    something(arg1, test(arg2))
  • adding pairs in conditionals:

    if |blah != nil       type test( ->
    if test(blah) != nil
  • autocorrection:

    something(|arg1, arg2)        type: test( ->
    something(test(|arg1), arg2)  move cursor after last ) and type ) ->
    something(test(arg1), arg2)|
    something(test(arg1, arg2))|

Installation & Usage

Plug 'vim-autosurround'

Plugin provides only python API.

Extension

Plugin provides API, which can be used to extend surround logic:

  • index = autosurround.register_finder(callback), callback is a function
    of one argument cursor, which is vim.current.window.cursor.

callback should return tuple (line, column) with position, which will be
used for inserting pair character or None, if callback is not able to
find position.

index can be used for unregister_finder(index).

  • autosurround.unregister_finder(index) will remove previously added
    callback.

添加新评论