太好用了,括号相关的各种麻烦都一一解决,剩下的就是熟练,熟练,在熟练了。呵呵

连教程都做得这么好,先放这里,以后慢慢翻译。

Auto Pairs

Insert or delete brackets, parens, quotes in pair.

Installation

copy plugin/auto-pairs.vim to ~/.vim/plugin

or if you are using pathogen:

git clone git://github.com/jiangmiao/auto-pairs.git ~/.vim/bundle/auto-pairs

Features

  • Insert in pair

    input: [
    output: [|]
  • Delete in pair

    input: foo[<BS>]
    output: foo
  • Insert new indented line after Return

    input: {|} (press <CR> at |)
    output: {
    |
    }
  • Insert spaces before closing characters, only for [], (), {}

    input: {|} (press <SPACE> at |)
    output: { | } input: {|} (press <SPACE>foo} at |)
    output: { foo }| input: '|' (press <SPACE> at |)
    output: ' |'
  • Skip ' when inside a word

    input: foo| (press ' at |)
    output: foo'
  • Skip closed bracket.

    input: []
    output: []
  • Ignore auto pair when previous character is \

    input: "\'
    output: "\'"
  • Fast Wrap

    input: |'hello' (press (<M-e> at |)
    output: ('hello') wrap string, only support c style string
    input: |'h\\el\'lo' (press (<M-e> at |)
    output ('h\\ello\'') input: |[foo, bar()] (press (<M-e> at |)
    output: ([foo, bar()])
  • Quick jump to closed pair.

    input:
    {
    something;|
    } (press } at |) output:
    { }|
  • Support ``` ''' and """

    input:
    ''' output:
    '''|'''
  • Delete Repeated Pairs in one time

    input: """|""" (press <BS> at |)
    output: | input: {{|}} (press <BS> at |)
    output: | input: [[[[[[|]]]]]] (press <BS> at |)
    output: |
  • Fly Mode

     input: if(a[3)
    output: if(a[3])| (In Fly Mode)
    output: if(a[3)]) (Without Fly Mode) input:
    {
    hello();|
    world();
    } (press } at |) output:
    {
    hello();
    world();
    }| (then press <M-b> at | to do backinsert)
    output:
    {
    hello();}|
    world();
    } See Fly Mode section for details

Fly Mode

Fly Mode will always force closed-pair jumping instead of inserting. only for ")", "}", "]"

If jumps in mistake, could use AutoPairsBackInsert(Default Key: <M-b>) to jump back and insert closed pair.

the most situation maybe want to insert single closed pair in the string, eg ")"

Fly Mode is DISABLED by default.

add let g:AutoPairsFlyMode = 1 .vimrc to turn it on

Default Options:

let g:AutoPairsFlyMode = 0
let g:AutoPairsShortcutBackInsert = '<M-b>'

Shortcuts

System Shortcuts:
<CR> : Insert new indented line after return if cursor in blank brackets or quotes.
<BS> : Delete brackets in pair
<M-p> : Toggle Autopairs (g:AutoPairsShortcutToggle)
<M-e> : Fast Wrap (g:AutoPairsShortcutFastWrap)
<M-n> : Jump to next closed pair (g:AutoPairsShortcutJump)
<M-b> : BackInsert (g:AutoPairsShortcutBackInsert) If <M-p> <M-e> or <M-n> conflict with another keys or want to bind to another keys, add let g:AutoPairsShortcutToggle = '<another key>' to .vimrc, if the key is empty string '', then the shortcut will be disabled.

Options

  • g:AutoPairs

    Default: {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`'}
  • b:AutoPairs

    Default: g:AutoPairs
    
    Buffer level pairs set.
  • g:AutoPairsShortcutToggle

    Default: '<M-p>'
    
    The shortcut to toggle autopairs.
  • g:AutoPairsShortcutFastWrap

    Default: '<M-e>'
    
    Fast wrap the word. all pairs will be consider as a block (include <>).
    (|)'hello' after fast wrap at |, the word will be ('hello')
    (|)<hello> after fast wrap at |, the word will be (<hello>)
  • g:AutoPairsShortcutJump

    Default: '<M-n>'
    
    Jump to the next closed pair
  • g:AutoPairsMapBS

    Default : 1
    
    Map <BS> to delete brackets, quotes in pair
    execute 'inoremap <buffer> <silent> <BS> <C-R>=AutoPairsDelete()<CR>'
  • g:AutoPairsMapCh

    Default : 1
    
    Map <C-h> to delete brackets, quotes in pair
  • g:AutoPairsMapCR

    Default : 1
    
    Map <CR> to insert a new indented line if cursor in (|), {|} [|], '|', "|"
    execute 'inoremap <buffer> <silent> <CR> <C-R>=AutoPairsReturn()<CR>'
  • g:AutoPairsCenterLine

    Default : 1
    
    When g:AutoPairsMapCR is on, center current line after return if the line is at the bottom 1/3 of the window.
  • g:AutoPairsMapSpace

    Default : 1
    
    Map <space> to insert a space after the opening character and before the closing one.
    execute 'inoremap <buffer> <silent> <CR> <C-R>=AutoPairsSpace()<CR>'
  • g:AutoPairsFlyMode

    Default : 0
    
    set it to 1 to enable FlyMode.
    see FlyMode section for details.
  • g:AutoPairsMultilineClose

    Default : 1
    
    When you press the key for the closing pair (e.g. `)`) it jumps past it.
    If set to 1, then it'll jump to the next line, if there is only whitespace.
    If set to 0, then it'll only jump to a closing pair on the same line.
  • g:AutoPairsShortcutBackInsert

    Default : <M-b>
    
    Work with FlyMode, insert the key at the Fly Mode jumped postion

Buffer Level Pairs Setting

Set b:AutoPairs before BufEnter

eg:

" When the filetype is FILETYPE then make AutoPairs only match for parenthesis
au Filetype FILETYPE let b:AutoPairs = {"(": ")"}

TroubleShooting

The script will remap keys ([{'"}]) <BS>,
If auto pairs cannot work, use :imap ( to check if the map is corrected.
The correct map should be <C-R>=AutoPairsInsert("\(")<CR>
Or the plugin conflict with some other plugins.
use command :call AutoPairsInit() to remap the keys.
  • How to insert parens purely

    There are 3 ways

    1. use Ctrl-V ) to insert paren without trigger the plugin.

    2. use Alt-P to turn off the plugin.

    3. use DEL or x to delete the character insert by plugin.

  • Swedish Character Conflict

    Because AutoPairs uses Meta(Alt) key as shortcut, it is conflict with some Swedish character such as 氓.

    To fix the issue, you need remap or disable the related shortcut.

vim:隆重推荐括号补全插件--auto-pairs的更多相关文章

  1. VIM自动补全插件 - YouCompleteMe--"大神级vim补全插件"

    VIM自动补全插件 - YouCompleteMe 序言 vim 之所以被称为编辑器之神多半归功于其丰富的可DIY的灵活插件功能,( 例如vim下的这款神级般的代码补全插件YouCompleteMe) ...

  2. Vimer的福音 新时代的Vim C++自动补全插件 clang_complete

    使用vim的各位肯定尝试过各种各样的自动补全插件,比如说大名鼎鼎的 OmniCppComplete .这一类的插件都是对 Ctags 生成的符号表进行字符串匹配来获得可能的补全项.他们在编写 C 代码 ...

  3. 新时代的Vim C++自动补全插件 clang_complete

    Vimer的福音 新时代的Vim C++自动补全插件 clang_complete   使用vim的各位肯定尝试过各种各样的自动补全插件,比如说大名鼎鼎的 OmniCppComplete .这一类的插 ...

  4. vim python自动补全插件:pydiction

    vim python自动补全插件:pydiction 可以实现下面python代码的自动补全: 1.简单python关键词补全 2.python 函数补全带括号 3.python 模块补全 4.pyt ...

  5. vim自动补全插件YouCompleteMe

    前言 Valloric/YouCompleteMe可以说是vim安装最复杂的插件之一,但是一旦装好,却又是非常好用的.YouCompleteMe简称ycm 在安装折腾的过程中,我再一次的体会到,除了官 ...

  6. Archlinux YouCompleteMe+syntastic vim自己主动补全插件,显示缩进和状态栏美化,爽心悦目的vim

    Archlinux 安装和配置vim补全插件YouCompleteMe的过程. 參考: https://github.com/Valloric/YouCompleteMe https://github ...

  7. Windows 10环境安装VIM代码补全插件YouCompleteMe

    Windows 10环境安装VIM代码补全插件YouCompleteMe 折腾一周也没搞定Windows下安装VIM代码补全插件YouCompleteMe,今天在家折腾一天总算搞定了.关键问题是在于P ...

  8. 【转】Vim自动补全插件----YouCompleteMe安装与配置

    原文网址:http://www.cnblogs.com/zhongcq/p/3630047.html 使用Vim编写程序少不了使用自动补全插件,在Linux下有没有类似VS中的Visual Assis ...

  9. Vim自动补全插件----YouCompleteMe安装与配置

    Vim自动补全插件----YouCompleteMe安装与配置 使用Vim编写程序少不了使用自动补全插件,在Linux下有没有类似VS中的Visual Assist X这么方便快捷的补全插件呢?以前用 ...

随机推荐

  1. C#.NET常见问题(FAQ)-使用SharpDevelop开发 如何在项目中添加类文件

    点击文件-新建-文件,然后再工程内创建文件   或者工程-添加-新建项     更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: http://i.youku.com/acetaohai12 ...

  2. spring源代码系列(一)sring源代码编译 spring源代码下载 spring源代码阅读

    想对spring框架进行深入的学习一下,看看源码,提升和沉淀下自己,工欲善其事必先利其器,还是先搭建好开发环境吧. 环境搭建 sping源代码之前是svn管理,如今已经迁移到了github中了.新版本 ...

  3. CAD批量合并文件

    要求:将整饰完成504幅单独的宗地图合并成一张总图,合并后,去掉其他要素,只保留毕合的权属线. 解决: 1.合并dwg文件,除了手工粘贴复制外,最先想到的是插入块,即用Insert命令插入,测试结果可 ...

  4. 网上下载的 chm 文件打开后右侧内容显示空白

    有时候在网上下载的chm文件打不开,或者打开后右侧内容显示空白,可尝试以下方法解决. 1.当你第一次打开文件时,会弹出如下警告窗口,点击打开: 打开后发现不管你怎么点,右边始终是空白的,有时候也会提示 ...

  5. JavaScript 之 特殊运算符

    一.=== 下面的规则用来判断两个值是否===相等:       首先,== equality 等同,=== identity 恒等.       ==, 两边值类型不同的时候,要先进行类型转换,再比 ...

  6. NDK 编译armebai-v7a的非4字节对齐crash Fatal signal 7 (SIGSEGV) 错误解决

    一直都是编译armabi的.没有不论什么问题,这个架构是软件模拟浮点运算的. 后来看到NDK文档上说armabi-v7a是针对有硬件处理浮点计算的arm cpu的. 于是就改动配置编译armebai- ...

  7. KVC简介 -字典转模型,模型转字典

    // 下面两个方法.都属于 KVC 的方法 // KVC 是 cocoa 的大招.间接给对象属性设置数值 // 程序运行过程中,动态给对象属性设置数值.不关心 .h 中是怎样定义的 //      仅 ...

  8. SqlServer数据库分离与附加

    SQL Server提供了“分离/附加”数据库.“备份/还原”数据库.复制数据库等多种数据库的备份和恢复方法.这里介绍一种学习中常用的“分离/附加”方法,类似于大家熟悉的“文件拷贝”方法,即把数据库文 ...

  9. C++ union使用注意

    union在我们敲代码的时候的使用概率远远小于struct.所以我们常常不太关心她.就知道他是使用内存复用技术.同一个时刻,他仅仅能存在一个成员的值. C中,我们在union中能够包括struct的, ...

  10. 通过修改css文件来观察openerp表单中的col和colspan

    适用版本 openerp 6.1.1 问题的提出 在openerp的表单定义中, 要使用 colspan和col 指你定各个元素的占位, 前者说明了本元素占据其所在容器的列数, 后者说明了本元素作为容 ...