add Fast Wrap feature

This commit is contained in:
jiangfriend@gmail.com 2011-06-10 02:23:47 +08:00
parent e893ae3d48
commit b0a61e7ab7
2 changed files with 31 additions and 16 deletions

View File

@ -26,7 +26,7 @@ Features
}
### Skip closed bracket.
call feedkeys(
input: []
output: []
@ -35,6 +35,10 @@ Features
input: "\'
output: "\'"
### Fast Wrap
input: |'hello' (press (<M-e> at|)
output: ('hello')
Shortcuts
---------
@ -43,6 +47,7 @@ Shortcuts
<CR> : Insert new indented line after return if cursor in blank brackets or quotes.
<BS> : Delete brackets in pair
<M-p> : Toggle Autopairs
<M-e> : Fast Wrap
Optional Shortcuts:
could be turn off by let g:AutoPairsShortcuts = 0
@ -62,6 +67,14 @@ Options
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:AutoPairsShortcuts
Default: 1

View File

@ -1,7 +1,7 @@
" Insert or delete brackets, parens, quotes in pairs.
" Maintainer: JiangMiao <jiangfriend@gmail.com>
" Last Change: 2011-06-07
" Version: 1.0.2
" Last Change: 2011-06-10
" Version: 1.0.3
" Homepage: http://www.vim.org/scripts/script.php?script_id=3599
" Repository: https://github.com/jiangmiao/auto-pairs
@ -21,6 +21,8 @@ end
if !exists('g:AutoPairs')
let g:AutoPairs = {'(':')', '[':']', '{':'}',"'":"'",'"':'"'}
end
let g:AutoExtraPairs = copy(g:AutoPairs)
let g:AutoExtraPairs['<'] = '>'
if !exists('g:AutoPairsMapBS')
let g:AutoPairsMapBS = 1
@ -112,21 +114,21 @@ function! AutoPairsExtend()
let line = getline('.')
let current_char = line[col('.')-1]
let next_char = line[col('.')]
if has_key(g:AutoPairsClosedPairs, current_char)
if has_key(g:AutoPairs, next_char)
let open = next_char
let close = g:AutoPairs[next_char]
let quote_pattern = '(?:\\\|\"\|[^"])*'
echoe 'search pair '.open.' '.close
call searchpair(open, '', close, 'W')
end
execute "normal! a".current_char."\<LEFT>"
return ''
normal! x
if match(next_char, '\s') != -1
call search('\S', 'W')
let next_char = getline('.')[col('.')-1]
end
return ''
if has_key(g:AutoExtraPairs, next_char)
let close = g:AutoExtraPairs[next_char]
call search(close, 'W')
return "\<RIGHT>".current_char."\<LEFT>"
else
execute "normal! ea".current_char
return ""
end
endfunction
function! AutoPairsMap(key)