Browse files

Version 1.3.0

Auto insert triple pairs.
Support deleting repeated pairs in one time.
  • Loading branch information...
1 parent d769b39 commit 23d7184ffb6a50a625b7395d201ce4b98ac04525 @jiangmiao jiangmiao committed with Feb 16, 2013
Showing with 48 additions and 14 deletions.
  1. +22 −11 README.md
  2. +26 −3 plugin/auto-pairs.vim
View
33 README.md
@@ -83,7 +83,18 @@ Features
'''
output:
- '''
+ '''|'''
+
+* Delete Repeated Pairs in one time
+
+ input: """|""" (press <BS> at |)
+ output: |
+
+ input: {{|}} (press <BS> at |)
+ output: |
+
+ input: [[[[[[|]]]]]] (press <BS> at |)
+ output: |
* Fly Mode
@@ -259,7 +270,7 @@ Compatible with Vimwiki - [issue #19](https://github.com/jiangmiao/auto-pairs/is
Description: When works with vimwiki `<CR>` will output `<SNR>xx_CR()`
Reason: vimwiki uses `<expr>` on mapping `<CR>` that auto-pairs cannot expanding.
Solution A: Add
-
+
" Copy from vimwiki.vim s:CR function for CR remapping
function! VimwikiCR()
let res = vimwiki#lst#kbd_cr()
@@ -269,23 +280,23 @@ Compatible with Vimwiki - [issue #19](https://github.com/jiangmiao/auto-pairs/is
return res
endfunction
autocmd filetype vimwiki inoremap <buffer> <silent> <CR> <C-R>=VimwikiCR()<CR><C-R>=AutoPairsReturn()<CR>
-
+
to .vimrc, it will make vimwiki and auto-pairs 'Return' feature works together.
Solution B: add `let g:AutoPairsMapCR = 0` to .vimrc to disable `<CR>` mapping.
-
+
Compatible with viki - [issue #25](https://github.com/jiangmiao/auto-pairs/issues/25)
-
+
Description: When works with viki `<CR>` will output viki#ExprMarkInexistentInElement('ParagraphVisible','<CR>')
Reason: viki uses `<expr>` on mapping `<CR>` that auto-pairs cannot expanding.
- Solution A: Add
-
- autocmd filetype viki inoremap <buffer> <silent> <CR> <C-R>=viki#ExprMarkInexistentInElement('ParagraphVisible',"\n")<CR><C-R>=AutoPairsReturn()<CR>`
-
+ Solution A: Add
+
+ autocmd filetype viki inoremap <buffer> <silent> <CR> <C-R>=viki#ExprMarkInexistentInElement('ParagraphVisible',"\n")<CR><C-R>=AutoPairsReturn()<CR>`
+
to .vimrc, it will make viki and auto-pairs works together.
-
+
Solution B: add `let g:AutoPairsMapCR = 0` to .vimrc to disable `<CR>` mapping.
-
+
Remarks: Solution A need NOT add `let g:AutoPairsMapCR = 0` to .vimrc, if Solution A still cannot work, then have to use Solution B to disable auto-pairs `<CR>`.
Breaks '.' - [issue #3](https://github.com/jiangmiao/auto-pairs/issues/3)
View
29 plugin/auto-pairs.vim
@@ -1,8 +1,8 @@
" Insert or delete brackets, parens, quotes in pairs.
" Maintainer: JiangMiao <jiangfriend@gmail.com>
" Contributor: camthompson
-" Last Change: 2013-01-15
-" Version: 1.2.9
+" Last Change: 2013-02-16
+" Version: 1.3.0
" Homepage: http://www.vim.org/scripts/script.php?script_id=3599
" Repository: https://github.com/jiangmiao/auto-pairs
@@ -142,7 +142,7 @@ function! AutoPairsInsert(key)
let pprev_char = line[col('.')-3]
if pprev_char == open && prev_char == open
" Double pair found
- return a:key
+ return repeat(a:key, 4) . repeat("\<LEFT>", 3)
end
end
@@ -170,12 +170,35 @@ function! AutoPairsDelete()
return "\<BS>\<DEL>"
endif
+ " Delete Repeated Pair eg: '''|''' [[|]] {{|}}
+ if has_key(b:AutoPairs, prev_char)
+ let times = 0
+ let p = -1
+ while get(prev_chars, p, '') == prev_char
+ let p = p - 1
+ let times = times + 1
+ endwhile
+
+ let close = b:AutoPairs[prev_char]
+ let left = repeat(prev_char, times)
+ let right = repeat(close, times)
+
+ let before = strpart(line, pos-times, times)
+ let after = strpart(line, pos, times)
+ if left == before && right == after
+ return repeat("\<BS>\<DEL>", times)
+ end
+ end
+
+
if has_key(b:AutoPairs, prev_char)
let close = b:AutoPairs[prev_char]
if match(line,'^\s*'.close, col('.')-1) != -1
+ " Delete (|___)
let space = matchstr(line, '^\s*', col('.')-1)
return "\<BS>". repeat("\<DEL>", len(space)+1)
elseif match(line, '^\s*$', col('.')-1) != -1
+ " Delete (|__\n___)
let nline = getline(line('.')+1)
if nline =~ '^\s*'.close
let space = matchstr(nline, '^\s*')

0 comments on commit 23d7184

Please sign in to comment.