vim:隆重推荐括号补全插件--auto-pairs
2016-07-07 21:34
465 查看
##太好用了,括号相关的各种麻烦都一一解决,剩下的就是熟练,熟练,在熟练了。呵呵
##连教程都做得这么好,先放这里,以后慢慢翻译。
or if you are using
Delete in pair
Insert new indented line after Return
Insert spaces before closing characters, only for [], (),
Skip ' when inside a word
Skip closed bracket.
Ignore auto pair when previous character is \
Fast Wrap
Quick jump to closed pair.
Support ``` ''' and """
Delete Repeated Pairs in one time
Fly Mode
If jumps in mistake, could use AutoPairsBackInsert(Default Key:
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:
b:AutoPairs
g:AutoPairsShortcutToggle
g:AutoPairsShortcutFastWrap
g:AutoPairsShortcutJump
g:AutoPairsMapBS
g:AutoPairsMapCh
g:AutoPairsMapCR
g:AutoPairsCenterLine
g:AutoPairsMapSpace
g:AutoPairsFlyMode
g:AutoPairsMultilineClose
g:AutoPairsShortcutBackInsert
eg:
How to insert parens purely
There are 3 ways
use Ctrl-V ) to insert paren without trigger the plugin.
use Alt-P to turn off the plugin.
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.
##连教程都做得这么好,先放这里,以后慢慢翻译。
Auto Pairs
Insert or delete brackets, parens, quotes in pair.Installation
copy plugin/auto-pairs.vim to ~/.vim/pluginor if you are using
pathogen:
git clone git://github.com/jiangmiao/auto-pairs.git ~/.vim/bundle/auto-pairs
Features
Insert in pairinput: [ 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:AutoPairsDefault: {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`'}
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 BufEntereg:
" 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
use Ctrl-V ) to insert paren without trigger the plugin.
use Alt-P to turn off the plugin.
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.
相关文章推荐
- Leetcode Climbing Stairs
- FSS指定磁盘布局进行vxvm的mirror-stripe(raid01)卷的制作
- 在VXVM环境下配置raid01和raid10卷,以及2者间的转换方法
- 关于友盟SDK和支付宝SDK类重复的问题解决--ava.util.zip.ZipException: duplicate entry: com/ut/device/AidCallback.class
- poj 1681 Painter's Problem 高斯消元 枚举自由变元
- leetcode 373. Find K Pairs with Smallest Sums
- Bootloader - Main system - Recovery的三角关系
- 如何修改Main.storyboard文件里模拟器的大小
- solairs 挂载asm磁阵
- http://blog.csdn.net/xiamizy/article/details/40781939
- Determining IP information for eth0...failed
- WINPE3.0集成RAID阵列卡驱动的实现方法
- 使用Robomongo 连接MongoDB 3.x 报 Authorization failed 解决办法(转)
- Failed to load class "org.slf4j.impl.StaticLoggerBinder"异常解决办法
- INS-06002: Authentication failed
- aidl长连接小记
- Codeforces Round #360 (Div. 1) B. Remainders Game(中国剩余定理)
- [Saltstack]-{grains,pillar}[二]
- leetcode336. Palindrome Pairs
- Chainer's simple implementation of fast R-CNN