New feature: Move character under the cursor to the pair.

This commit is contained in:
Miao Jiang 2017-06-17 01:23:20 +08:00
parent 20ec5b043f
commit 6afc850e24
2 changed files with 40 additions and 3 deletions

View File

@ -67,6 +67,14 @@ Features
input: |[foo, bar()] (press (<M-e> at |)
output: ([foo, bar()])
* Quick move char to closed pair
input: (|){["foo"]} (press <M-}> at |)
output: ({["foo"]}|)
input: |[foo, bar()] (press (<M-]> at |)
output: ([foo, bar()]|)
* Quick jump to closed pair.
input:
@ -249,6 +257,13 @@ Options
Work with FlyMode, insert the key at the Fly Mode jumped postion
* g:AutoPairsMoveCharacter
Default: "()[]{}\"'"
Map <M-(> <M-)> <M-[> <M-]> <M-{> <M-}> <M-"> <M-'> to
move character under the cursor to the pair.
Buffer Level Pairs Setting
--------------------------

View File

@ -1,8 +1,8 @@
" Insert or delete brackets, parens, quotes in pairs.
" Maintainer: JiangMiao <jiangfriend@gmail.com>
" Contributor: camthompson
" Last Change: 2013-07-13
" Version: 1.3.2
" Last Change: 2017-06-17
" Version: 1.3.3
" Homepage: http://www.vim.org/scripts/script.php?script_id=3599
" Repository: https://github.com/jiangmiao/auto-pairs
" License: MIT
@ -49,6 +49,10 @@ if !exists('g:AutoPairsShortcutFastWrap')
let g:AutoPairsShortcutFastWrap = '<M-e>'
end
if !exists('g:AutoPairsMoveCharacter')
let g:AutoPairsMoveCharacter = "()[]{}\"'"
end
if !exists('g:AutoPairsShortcutJump')
let g:AutoPairsShortcutJump = '<M-n>'
endif
@ -356,6 +360,7 @@ function! AutoPairsMap(key)
let escaped_key = substitute(key, "'", "''", 'g')
" use expr will cause search() doesn't work
execute 'inoremap <buffer> <silent> '.key." <C-R>=AutoPairsInsert('".escaped_key."')<CR>"
endfunction
function! AutoPairsToggle()
@ -369,6 +374,12 @@ function! AutoPairsToggle()
return ''
endfunction
function! AutoPairsMoveCharacter(key)
let c = getline(".")[col(".")-1]
let escaped_key = substitute(a:key, "'", "''", 'g')
return "\<DEL>\<ESC>:call search("."'".escaped_key."'".")\<CR>a".c."\<LEFT>"
endfunction
function! AutoPairsReturn()
if b:autopairs_enabled == 0
return ''
@ -425,13 +436,19 @@ endfunction
function! AutoPairsInit()
let b:autopairs_loaded = 1
if !exists('b:autopairs_enabled')
let b:autopairs_enabled = 1
end
let b:AutoPairsClosedPairs = {}
if !exists('b:AutoPairs')
let b:AutoPairs = g:AutoPairs
end
if !exists('b:AutoPairsMoveCharacter')
let b:AutoPairsMoveCharacter = g:AutoPairsMoveCharacter
end
" buffer level map pairs keys
for [open, close] in items(b:AutoPairs)
call AutoPairsMap(open)
@ -441,6 +458,11 @@ function! AutoPairsInit()
let b:AutoPairsClosedPairs[close] = open
endfor
for key in split(b:AutoPairsMoveCharacter, '\s*')
let escaped_key = substitute(key, "'", "''", 'g')
execute 'inoremap <silent> <buffer> <M-'.key."> <C-R>=AutoPairsMoveCharacter('".escaped_key."')<CR>"
endfor
" Still use <buffer> level mapping for <BS> <SPACE>
if g:AutoPairsMapBS
" Use <C-R> instead of <expr> for issue #14 sometimes press BS output strange words