1
1
" Insert or delete brackets, parens, quotes in pairs.
2
2
" Maintainer: JiangMiao <jiangfriend@gmail.com>
3
3
" Contributor: camthompson
4
- " Last Change: 2012-12-18
5
- " Version: 1.2.8
4
+ " Last Change: 2013-01-15
5
+ " Version: 1.2.9
6
6
" Homepage: http://www.vim.org/scripts/script.php?script_id=3599
7
7
" Repository: https://github.com/jiangmiao/auto-pairs
8
8
@@ -19,9 +19,6 @@ if !exists('g:AutoPairsParens')
19
19
let g: AutoPairsParens = {' (' :' )' , ' [' :' ]' , ' {' :' }' }
20
20
end
21
21
22
- let g: AutoExtraPairs = copy (g: AutoPairs )
23
- let g: AutoExtraPairs [' <' ] = ' >'
24
-
25
22
if ! exists (' g:AutoPairsMapBS' )
26
23
let g: AutoPairsMapBS = 1
27
24
end
@@ -90,7 +87,7 @@ function! AutoPairsInsert(key)
90
87
end
91
88
92
89
" The key is difference open-pair, then it means only for ) ] } by default
93
- if ! has_key (g : AutoPairs , a: key )
90
+ if ! has_key (b : AutoPairs , a: key )
94
91
let b: autopairs_saved_pair = [a: key , getpos (' .' )]
95
92
96
93
" Skip the character if current character is the same as input
@@ -116,7 +113,7 @@ function! AutoPairsInsert(key)
116
113
endif
117
114
118
115
" Fly Mode, and the key is closed-pairs, search closed-pair and jump
119
- if g: AutoPairsFlyMode && has_key (g : AutoPairsClosedPairs , a: key )
116
+ if g: AutoPairsFlyMode && has_key (b : AutoPairsClosedPairs , a: key )
120
117
if search (a: key , ' W' )
121
118
return " \<Right> "
122
119
endif
@@ -127,7 +124,7 @@ function! AutoPairsInsert(key)
127
124
end
128
125
129
126
let open = a: key
130
- let close = g : AutoPairs [open ]
127
+ let close = b : AutoPairs [open ]
131
128
132
129
if current_char == close && open == close
133
130
return " \<Right> "
@@ -169,12 +166,12 @@ function! AutoPairsDelete()
169
166
end
170
167
171
168
" Delete last two spaces in parens, work with MapSpace
172
- if has_key (g : AutoPairs , pprev_char) && prev_char == ' ' && current_char == ' '
169
+ if has_key (b : AutoPairs , pprev_char) && prev_char == ' ' && current_char == ' '
173
170
return " \<BS>\<DEL> "
174
171
endif
175
172
176
- if has_key (g : AutoPairs , prev_char)
177
- let close = g : AutoPairs [prev_char]
173
+ if has_key (b : AutoPairs , prev_char)
174
+ let close = b : AutoPairs [prev_char]
178
175
if match (line ,' ^\s*' .close , col (' .' )-1 ) != -1
179
176
let space = matchstr (line , ' ^\s*' , col (' .' )-1 )
180
177
return " \<BS> " . repeat (" \<DEL> " , len (space)+ 1 )
@@ -234,10 +231,10 @@ function! AutoPairsFastWrap()
234
231
let next_char = line [col (' .' )-1 ]
235
232
end
236
233
237
- if has_key (g : AutoPairs , next_char)
234
+ if has_key (b : AutoPairs , next_char)
238
235
let followed_open_pair = next_char
239
236
let inputed_close_pair = current_char
240
- let followed_close_pair = g : AutoPairs [next_char]
237
+ let followed_close_pair = b : AutoPairs [next_char]
241
238
if followed_close_pair != followed_open_pair
242
239
" TODO replace system searchpair to skip string and nested pair.
243
240
" eg: (|){"hello}world"} will transform to ({"hello})world"}
@@ -278,7 +275,7 @@ function! AutoPairsReturn()
278
275
let prev_char = pline[strlen (pline)-1 ]
279
276
let cmd = ' '
280
277
let cur_char = line [col (' .' )-1 ]
281
- if has_key (g : AutoPairs , prev_char) && g : AutoPairs [prev_char] == cur_char
278
+ if has_key (b : AutoPairs , prev_char) && b : AutoPairs [prev_char] == cur_char
282
279
if g: AutoPairsCenterLine && winline () * 3 >= winheight (0 ) * 2
283
280
" Use \<BS> instead of \<ESC>cl will cause the placeholder deleted
284
281
" incorrect. because <C-O>zz won't leave Normal mode.
@@ -328,14 +325,19 @@ endfunction
328
325
function ! AutoPairsInit ()
329
326
let b: autopairs_loaded = 1
330
327
let b: autopairs_enabled = 1
328
+ let b: AutoPairsClosedPairs = {}
329
+
330
+ if ! exists (' b:AutoPairs' )
331
+ let b: AutoPairs = g: AutoPairs
332
+ end
331
333
332
334
" buffer level map pairs keys
333
- for [open , close ] in items (g : AutoPairs )
335
+ for [open , close ] in items (b : AutoPairs )
334
336
call AutoPairsMap (open )
335
337
if open != close
336
338
call AutoPairsMap (close )
337
339
end
338
- let g : AutoPairsClosedPairs [close ] = open
340
+ let b : AutoPairsClosedPairs [close ] = open
339
341
endfor
340
342
341
343
" Still use <buffer> level mapping for <BS> <SPACE>
@@ -377,10 +379,11 @@ function! s:ExpandMap(map)
377
379
return map
378
380
endfunction
379
381
380
- function ! AutoPairsForceInit ()
382
+ function ! AutoPairsTryInit ()
381
383
if exists (' b:autopairs_loaded' )
382
384
return
383
385
end
386
+
384
387
" for auto-pairs starts with 'a', so the priority is higher than supertab and vim-endwise
385
388
"
386
389
" vim-endwise doesn't support <Plug>AutoPairsReturn
@@ -426,4 +429,4 @@ inoremap <silent> <SID>AutoPairsReturn <C-R>=AutoPairsReturn()<CR>
426
429
imap <script> <Plug> AutoPairsReturn <SID> AutoPairsReturn
427
430
428
431
429
- au BufEnter * :call AutoPairsForceInit ()
432
+ au BufEnter * :call AutoPairsTryInit ()
0 commit comments