Compare commits

...

3 Commits

Author SHA1 Message Date
Miao Jiang
39f06b873a Comptabile with <CR> <Plug>() mapping, fix #245 2019-02-27 17:11:39 +08:00
Miao Jiang
65a9f452f2 Obsolete wild close key by default, add custom close key, improve #242 2019-02-27 16:34:50 +08:00
Miao Jiang
fcf9f00f85 Add default pairs base on filetype, fix #241 2019-02-17 14:31:17 +08:00
2 changed files with 35 additions and 13 deletions

View File

@ -248,14 +248,6 @@ Options
Map <M-(> <M-)> <M-[> <M-]> <M-{> <M-}> <M-"> <M-'> to
move character under the cursor to the pair.
* g:AutoPairsWildClosedPair
Default: ']'
Jump over following closed pair
for pair {'begin': 'end//n]'}, e is not mapped, use wild closed pair ] to jump over 'end'
use <M-b> to back insert ] after jumping
Buffer Level Pairs Setting
--------------------------
@ -313,6 +305,7 @@ Multibyte Pairs
n - do not map the first charactor of closed pair to close key
m - close key jumps through multi line
s - close key jumps only in the same line
k[KEY] - map the close key to [KEY]
by default if open key equals close key the multi line is turn off
@ -321,6 +314,7 @@ Multibyte Pairs
"<?php":"?>" ? will jump through multi line
"<?php":"?>//s" force ? only jumping in the same line
"<?": "?>//n" do not jump totally
"<?": "?>//k]" use key ] to jump through ?>
for 'begin' 'end' pair, e is a charactor, if map e to jump will be annoy, so use modifier 'n' to skip key map

View File

@ -16,6 +16,28 @@ if !exists('g:AutoPairs')
let g:AutoPairs = {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '```':'```', '"""':'"""', "'''":"'''", "`":"`"}
end
" default pairs base on filetype
func! AutoPairsDefaultPairs()
if exists('b:autopairs_defaultpairs')
return b:autopairs_defaultpairs
end
let r = copy(g:AutoPairs)
let allPairs = {
\ 'vim': {'\v^\s*\zs"': ''},
\ 'rust': {'\w\zs<': '>', '&\zs''': ''},
\ 'php': {'<?': '?>//k]', '<?php': '?>//k]'}
\ }
for [filetype, pairs] in items(allPairs)
if &filetype == filetype
for [open, close] in items(pairs)
let r[open] = close
endfor
end
endfor
let b:autopairs_defaultpairs = r
return r
endf
if !exists('g:AutoPairsMapBS')
let g:AutoPairsMapBS = 1
end
@ -30,7 +52,7 @@ if !exists('g:AutoPairsMapCR')
end
if !exists('g:AutoPairsWildClosedPair')
let g:AutoPairsWildClosedPair = ']'
let g:AutoPairsWildClosedPair = ''
end
if !exists('g:AutoPairsMapSpace')
@ -161,7 +183,7 @@ endf
" au FileType html let b:AutoPairs = AutoPairsDefine({'<!--' : '-->'}, ['{'])
" add <!-- --> pair and remove '{' for html file
func! AutoPairsDefine(pairs, ...)
let r = copy(g:AutoPairs)
let r = AutoPairsDefaultPairs()
if a:0 > 0
for open in a:1
unlet r[open]
@ -241,7 +263,7 @@ func! AutoPairsInsert(key)
if close == ''
continue
end
if a:key == g:AutoPairsWildClosedPair || opt['mapclose'] && close[0] == a:key
if a:key == g:AutoPairsWildClosedPair || opt['mapclose'] && opt['key'] == a:key
" the close pair is in the same line
let m = matchstr(afterline, '^\v\s*\V'.close)
if m != ''
@ -453,10 +475,9 @@ func! AutoPairsInit()
end
if !exists('b:AutoPairs')
let b:AutoPairs = g:AutoPairs
let b:AutoPairs = AutoPairsDefaultPairs()
end
if !exists('b:AutoPairsMoveCharacter')
let b:AutoPairsMoveCharacter = g:AutoPairsMoveCharacter
end
@ -473,6 +494,7 @@ func! AutoPairsInit()
let o = open[-1:-1]
let c = close[0]
let opt = {'mapclose': 1, 'multiline':1}
let opt['key'] = c
if o == c
let opt['multiline'] = 0
end
@ -487,6 +509,11 @@ func! AutoPairsInit()
if m[2] =~ 's'
let opt['multiline'] = 0
end
let ks = matchlist(m[2], '\vk(.)')
if len(ks) > 0
let opt['key'] = ks[1]
let c = opt['key']
end
let close = m[1]
end
call AutoPairsMap(o)
@ -569,6 +596,7 @@ endf
func! s:ExpandMap(map)
let map = a:map
let map = substitute(map, '\(<Plug>\w\+\)', '\=maparg(submatch(1), "i")', 'g')
let map = substitute(map, '\(<Plug>([^)]*)\)', '\=maparg(submatch(1), "i")', 'g')
return map
endf