2011-05-22 13:11:23 -04:00
|
|
|
Auto Pairs
|
|
|
|
==========
|
|
|
|
Insert or delete brackets, parens, quotes in pair.
|
|
|
|
|
|
|
|
Installation
|
|
|
|
------------
|
|
|
|
copy plugin/auto-pairs.vim to ~/.vim/plugin
|
|
|
|
|
|
|
|
Features
|
|
|
|
--------
|
2011-06-09 14:32:17 -04:00
|
|
|
* Insert in pair
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2011-06-09 14:32:17 -04:00
|
|
|
input: [
|
|
|
|
output: [|]
|
2011-05-22 13:11:23 -04:00
|
|
|
|
2011-06-09 14:32:17 -04:00
|
|
|
* Delete in pair
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2011-06-09 14:32:17 -04:00
|
|
|
input: foo[<BS>
|
|
|
|
output: foo
|
2011-05-22 13:11:23 -04:00
|
|
|
|
2011-06-09 14:32:17 -04:00
|
|
|
* Insert new indented line after Return
|
2011-05-22 13:11:23 -04:00
|
|
|
|
2011-06-09 14:32:17 -04:00
|
|
|
input: {|} (press <CR> at |)
|
|
|
|
output: {
|
|
|
|
|
|
|
|
|
}
|
2011-05-22 13:11:23 -04:00
|
|
|
|
2011-12-14 04:00:45 -05:00
|
|
|
* Insert spaces before closing characters, only for [], (), {}
|
2011-12-13 17:05:59 -05:00
|
|
|
|
|
|
|
input: {|} (press <SPACE> at |)
|
|
|
|
output: { | }
|
|
|
|
|
2011-12-14 04:00:45 -05:00
|
|
|
input: {|} (press <SPACE>foo} at |)
|
|
|
|
output: { foo }|
|
|
|
|
|
|
|
|
input: '|' (press <SPACE> at |)
|
|
|
|
output: ' |'
|
|
|
|
|
2011-12-29 08:42:43 -05:00
|
|
|
* Skip ' when inside a word
|
|
|
|
|
|
|
|
input: foo| (press ' at |)
|
|
|
|
output: foo'
|
|
|
|
|
2011-06-09 14:32:17 -04:00
|
|
|
* Skip closed bracket.
|
2011-05-22 13:11:23 -04:00
|
|
|
|
2011-06-09 14:32:17 -04:00
|
|
|
input: []
|
|
|
|
output: []
|
2011-05-22 13:11:23 -04:00
|
|
|
|
2011-06-09 14:32:17 -04:00
|
|
|
* Ignore auto pair when previous character is \
|
2011-05-22 13:11:23 -04:00
|
|
|
|
2011-06-09 14:32:17 -04:00
|
|
|
input: "\'
|
|
|
|
output: "\'"
|
|
|
|
|
|
|
|
* Fast Wrap
|
|
|
|
|
|
|
|
input: |'hello' (press (<M-e> at|)
|
|
|
|
output: ('hello')
|
2011-06-09 14:23:47 -04:00
|
|
|
|
2011-12-21 23:30:04 -05:00
|
|
|
* Quick jump to closed pair.
|
2012-05-13 21:54:25 -04:00
|
|
|
|
|
|
|
input:
|
2011-12-21 23:30:04 -05:00
|
|
|
{
|
|
|
|
something;|
|
|
|
|
}
|
|
|
|
|
|
|
|
(press } at |)
|
|
|
|
|
|
|
|
output:
|
|
|
|
{
|
|
|
|
|
|
|
|
}|
|
2011-06-07 00:40:51 -04:00
|
|
|
|
2012-01-17 00:17:21 -05:00
|
|
|
* Support ``` ''' and """
|
|
|
|
|
|
|
|
input:
|
|
|
|
'''
|
|
|
|
|
|
|
|
output:
|
|
|
|
'''
|
|
|
|
|
2012-05-13 21:54:25 -04:00
|
|
|
* Fly Mode
|
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
input: if(a[3)
|
|
|
|
output: if(a[3])| (In Fly Mode)
|
|
|
|
output: if(a[3)]) (Without Fly Mode)
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
input:
|
|
|
|
{
|
|
|
|
hello();|
|
|
|
|
world();
|
|
|
|
}
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
(press } at |)
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
output:
|
|
|
|
{
|
|
|
|
hello();
|
|
|
|
world();
|
|
|
|
}|
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
(then press <M-b> at | to do backinsert)
|
|
|
|
output:
|
|
|
|
{
|
|
|
|
hello();}|
|
|
|
|
world();
|
|
|
|
}
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
See Fly Mode section for details
|
2012-05-13 21:54:25 -04:00
|
|
|
|
|
|
|
Fly Mode
|
|
|
|
--------
|
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
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 ")"
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
Default Options:
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
let g:AutoPairsFlyMode = 1
|
|
|
|
let g:AutoPairsShortcutBackInsert = '<M-b>'
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2011-06-07 00:40:51 -04:00
|
|
|
Shortcuts
|
|
|
|
---------
|
|
|
|
|
|
|
|
System Shortcuts:
|
|
|
|
<CR> : Insert new indented line after return if cursor in blank brackets or quotes.
|
|
|
|
<BS> : Delete brackets in pair
|
2012-03-20 01:13:39 -04:00
|
|
|
<M-p> : Toggle Autopairs (g:AutoPairsShortcutToggle)
|
|
|
|
<M-e> : Fast Wrap (g:AutoPairsShortcutFastWrap)
|
|
|
|
<M-n> : Jump to next closed pair (g:AutoPairsShortcutJump)
|
2012-05-14 02:23:08 -04:00
|
|
|
<M-b> : BackInsert
|
2011-06-07 00:40:51 -04:00
|
|
|
|
2012-03-20 01:13:39 -04:00
|
|
|
If <M-p> <M-e> or <M-n> conflict with another keys or want to bind to another keys, add
|
|
|
|
|
2012-05-13 21:54:25 -04:00
|
|
|
let g:AutoPairShortcutToggle = '<another key>'
|
2012-03-20 01:13:39 -04:00
|
|
|
|
|
|
|
to .vimrc, it the key is empty string '', then the shortcut will be disabled.
|
2011-06-07 00:40:51 -04:00
|
|
|
|
2011-05-22 13:11:23 -04:00
|
|
|
Options
|
|
|
|
-------
|
|
|
|
* g:AutoPairs
|
|
|
|
|
2012-01-17 00:17:21 -05:00
|
|
|
Default: {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`'}
|
2011-06-07 00:40:51 -04:00
|
|
|
|
|
|
|
* g:AutoPairsShortcutToggle
|
|
|
|
|
|
|
|
Default: '<M-p>'
|
|
|
|
|
|
|
|
The shortcut to toggle autopairs.
|
2011-05-22 13:11:23 -04:00
|
|
|
|
2011-06-09 14:23:47 -04:00
|
|
|
* g:AutoPairsShortcutFastWrap
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2011-06-09 14:23:47 -04:00
|
|
|
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>)
|
|
|
|
|
2012-03-20 01:13:39 -04:00
|
|
|
* g:AutoPairsShortcutJump
|
2011-06-07 00:40:51 -04:00
|
|
|
|
2012-03-20 01:13:39 -04:00
|
|
|
Default: '<M-n>'
|
2011-05-22 13:11:23 -04:00
|
|
|
|
2012-03-20 01:13:39 -04:00
|
|
|
Jump to the next closed pair
|
2011-05-22 13:11:23 -04:00
|
|
|
|
2011-06-07 00:40:51 -04:00
|
|
|
* g:AutoPairsMapBS
|
|
|
|
|
|
|
|
Default : 1
|
|
|
|
|
|
|
|
Map <BS> to delete brackets, quotes in pair
|
|
|
|
execute 'inoremap <buffer> <silent> <BS> <C-R>=AutoPairsDelete()<CR>'
|
|
|
|
|
|
|
|
* 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.
|
|
|
|
|
2011-12-13 17:05:59 -05:00
|
|
|
* g:AutoPairsMapSpace
|
|
|
|
|
|
|
|
Default : 1
|
|
|
|
|
|
|
|
Map <space> to insert a space after the opening character and before the closing one.
|
2011-12-14 04:00:45 -05:00
|
|
|
execute 'inoremap <buffer> <silent> <CR> <C-R>=AutoPairsSpace()<CR>'
|
2011-12-13 17:05:59 -05:00
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
* g:AutoPairsFlyMode
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
Default : 1
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
see FlyMode section for details.
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
* g:AutoPairsShortcutBackInsert
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
Default : <M-b>
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2012-05-14 02:23:08 -04:00
|
|
|
Work with FlyMode, insert the key at the Fly Mode jumped postion
|
2012-05-13 21:54:25 -04:00
|
|
|
|
2011-05-22 13:11:23 -04:00
|
|
|
TroubleShooting
|
|
|
|
---------------
|
2012-05-13 21:54:25 -04:00
|
|
|
The script will remap keys ([{'"}]) <BS>,
|
2011-05-22 13:11:23 -04:00
|
|
|
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.
|
|
|
|
|
2011-12-14 04:00:45 -05:00
|
|
|
|
|
|
|
* How to insert parens purely
|
|
|
|
|
|
|
|
There are 3 ways
|
2011-12-21 23:30:04 -05:00
|
|
|
|
|
|
|
1. use Ctrl-V ) to insert paren without trigger the plugin.
|
|
|
|
|
|
|
|
2. use Alt-P to turn off the plugin.
|
|
|
|
|
|
|
|
3. use DEL or <C-O>x to delete the character insert by plugin.
|
|
|
|
|
2011-12-29 08:42:43 -05:00
|
|
|
|
|
|
|
Contributors
|
|
|
|
------------
|
|
|
|
* [camthompson](https://github.com/camthompson)
|