22 Commits

Author SHA1 Message Date
23e77decb1 Bump version to 1.3.0 2013-02-16 14:02:32 +08:00
a9f53155e8 Update README. 2013-02-16 14:02:13 +08:00
c0593a61c7 Delete duplicated pairs in one time.
eg ```|``` {{|}} [[|]]
2013-02-12 14:02:25 +08:00
f11f3e5ee3 updated action on triple quote to add second line
changed the action on triple quote to add a closing quote and
start editing on the newly opened line inside the quotes.  the
only way to jump beyond the quotes is to escape and scroll down.
this is because a <CR> should give a new line, not jump to closing
quotes.
2013-02-11 09:56:54 -05:00
dd1ea6b1f7 Bump to v1.2.9 2013-01-15 15:27:23 +08:00
36ebfb6f29 improve #29 Buffer level pairs controlling. 2012-12-24 00:53:22 +08:00
0cabb1be77 bump to v1.2.8 2012-12-18 22:27:43 +08:00
ba81f659e7 fixes #27 <BS> cannot work when AutoPairs is turn off. 2012-12-01 13:06:15 +08:00
d59bc39f75 fixes incorrect AutoPairsDelete
[|{}
    ]

    press <BS> at | will become ]
2012-11-29 17:13:04 +08:00
713a33318a bump to v1.2.7 2012-11-02 09:27:26 +08:00
f8fa522790 Update vimwiki compatible hint. 2012-10-29 14:50:45 +08:00
7287467e64 update viki compatible hints in README 2012-10-25 01:18:19 +08:00
0ef881effd update viki compatible hints in README 2012-10-25 01:13:24 +08:00
8e9bee94c8 Add viki compatible hints to README 2012-10-25 00:59:21 +08:00
3c18515955 fixes #24 when equalprg is setting AutoPairsReturn cannot work well 2012-10-19 00:05:10 +08:00
652175babc bump to v1.2.6 2012-10-17 09:40:12 +08:00
9758a447cf fixes #23: Support typographer's quote pairs, such as ‘, ’, “, ” 2012-10-09 15:00:34 +08:00
1c5046f8c3 bump to v1.2.5 2012-09-15 12:08:47 +08:00
4a02e2c488 Fixes indentation incorrect when returning below 1/3 bottom of window. 2012-08-30 14:59:44 +08:00
28dc48fd9d bump to v1.2.4 2012-08-17 00:22:13 +08:00
27123dda7c update README 2012-08-11 22:30:11 +08:00
30c9108f80 fixes #20 Errors in pair creation that is split by ENTER 2012-08-11 22:29:33 +08:00
2 changed files with 134 additions and 30 deletions

View File

@ -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
@ -154,6 +165,12 @@ Options
Default: {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`'}
* b:AutoPairs
Default: g:AutoPairs
Buffer level pairs set.
* g:AutoPairsShortcutToggle
Default: '<M-p>'
@ -214,6 +231,16 @@ Options
Work with FlyMode, insert the key at the Fly Mode jumped postion
Buffer Level Pairs Setting
--------------------------
Set b:AutoPairs before BufEnter
eg:
" When the filetype is FILETYPE then make AutoPairs only match for parenthesis
au Filetype FILETYPE let b:AutoPairs = {"(": ")"}
TroubleShooting
---------------
The script will remap keys ([{'"}]) <BS>,
@ -242,11 +269,40 @@ 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: add `let g:AutoPairsMapCR = 0` to .vimrc to disable `<CR>` mapping.
Solution A: Add
" Copy from vimwiki.vim s:CR function for CR remapping
function! VimwikiCR()
let res = vimwiki#lst#kbd_cr()
if res == "\<CR>" && g:vimwiki_table_mappings
let res = vimwiki#tbl#kbd_cr()
endif
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>`
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)
Description: After entering insert mode and inputing `[hello` then leave insert mode by `<ESC>`, press '.' will insert 'hello' instead of '[hello]'.
Description: After entering insert mode and inputing `[hello` then leave insert
mode by `<ESC>`. press '.' will insert 'hello' instead of '[hello]'.
Reason: `[` actually equals `[]\<LEFT>` and \<LEFT> will break '.'
Solution: none

View File

@ -1,8 +1,8 @@
" Insert or delete brackets, parens, quotes in pairs.
" Maintainer: JiangMiao <jiangfriend@gmail.com>
" Contributor: camthompson
" Last Change: 2012-07-15
" Version: 1.2.3
" 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
@ -19,9 +19,6 @@ if !exists('g:AutoPairsParens')
let g:AutoPairsParens = {'(':')', '[':']', '{':'}'}
end
let g:AutoExtraPairs = copy(g:AutoPairs)
let g:AutoExtraPairs['<'] = '>'
if !exists('g:AutoPairsMapBS')
let g:AutoPairsMapBS = 1
end
@ -72,9 +69,12 @@ function! AutoPairsInsert(key)
end
let line = getline('.')
let prev_char = line[col('.')-2]
let current_char = line[col('.')-1]
let next_char = line[col('.')]
let pos = col('.') - 1
let next_chars = split(strpart(line, pos), '\zs')
let current_char = get(next_chars, 0, '')
let next_char = get(next_chars, 1, '')
let prev_chars = split(strpart(line, 0, pos), '\zs')
let prev_char = get(prev_chars, -1, '')
let eol = 0
if col('$') - col('.') <= 1
@ -87,7 +87,7 @@ function! AutoPairsInsert(key)
end
" The key is difference open-pair, then it means only for ) ] } by default
if !has_key(g:AutoPairs, a:key)
if !has_key(b:AutoPairs, a:key)
let b:autopairs_saved_pair = [a:key, getpos('.')]
" Skip the character if current character is the same as input
@ -113,7 +113,7 @@ function! AutoPairsInsert(key)
endif
" Fly Mode, and the key is closed-pairs, search closed-pair and jump
if g:AutoPairsFlyMode && has_key(g:AutoPairsClosedPairs, a:key)
if g:AutoPairsFlyMode && has_key(b:AutoPairsClosedPairs, a:key)
if search(a:key, 'W')
return "\<Right>"
endif
@ -124,7 +124,7 @@ function! AutoPairsInsert(key)
end
let open = a:key
let close = g:AutoPairs[open]
let close = b:AutoPairs[open]
if current_char == close && open == close
return "\<Right>"
@ -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
@ -150,26 +150,55 @@ function! AutoPairsInsert(key)
endfunction
function! AutoPairsDelete()
if !b:autopairs_enabled
return "\<BS>"
end
let line = getline('.')
let current_char = line[col('.')-1]
let prev_char = line[col('.')-2]
let pprev_char = line[col('.')-3]
let pos = col('.') - 1
let current_char = get(split(strpart(line, pos), '\zs'), 0, '')
let prev_chars = split(strpart(line, 0, pos), '\zs')
let prev_char = get(prev_chars, -1, '')
let pprev_char = get(prev_chars, -2, '')
if pprev_char == '\'
return "\<BS>"
end
" Delete last two spaces in parens, work with MapSpace
if has_key(g:AutoPairs, pprev_char) && prev_char == ' ' && current_char == ' '
if has_key(b:AutoPairs, pprev_char) && prev_char == ' ' && current_char == ' '
return "\<BS>\<DEL>"
endif
if has_key(g:AutoPairs, prev_char)
let close = g:AutoPairs[prev_char]
" 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)
else
elseif match(line, '^\s*$', col('.')-1) != -1
" Delete (|__\n___)
let nline = getline(line('.')+1)
if nline =~ '^\s*'.close
let space = matchstr(nline, '^\s*')
@ -225,10 +254,10 @@ function! AutoPairsFastWrap()
let next_char = line[col('.')-1]
end
if has_key(g:AutoPairs, next_char)
if has_key(b:AutoPairs, next_char)
let followed_open_pair = next_char
let inputed_close_pair = current_char
let followed_close_pair = g:AutoPairs[next_char]
let followed_close_pair = b:AutoPairs[next_char]
if followed_close_pair != followed_open_pair
" TODO replace system searchpair to skip string and nested pair.
" eg: (|){"hello}world"} will transform to ({"hello})world"}
@ -261,15 +290,28 @@ function! AutoPairsToggle()
endfunction
function! AutoPairsReturn()
if b:autopairs_enabled == 0
return ''
end
let line = getline('.')
let pline = getline(line('.')-1)
let prev_char = pline[strlen(pline)-1]
let cmd = ''
let cur_char = line[col('.')-1]
if has_key(g:AutoPairs, prev_char) && g:AutoPairs[prev_char] == cur_char
if g:AutoPairsCenterLine && winline() * 1.5 >= winheight(0)
if has_key(b:AutoPairs, prev_char) && b:AutoPairs[prev_char] == cur_char
if g:AutoPairsCenterLine && winline() * 3 >= winheight(0) * 2
" Use \<BS> instead of \<ESC>cl will cause the placeholder deleted
" incorrect. because <C-O>zz won't leave Normal mode.
" Use \<DEL> is a bit wierd. the character before cursor need to be deleted.
let cmd = " \<C-O>zz\<ESC>cl"
end
" If equalprg has been set, then avoid call =
" https://github.com/jiangmiao/auto-pairs/issues/24
if &equalprg != ''
return "\<ESC>O".cmd
endif
" conflict with javascript and coffee
" javascript need indent new line
" coffeescript forbid indent new line
@ -306,14 +348,19 @@ endfunction
function! AutoPairsInit()
let b:autopairs_loaded = 1
let b:autopairs_enabled = 1
let b:AutoPairsClosedPairs = {}
if !exists('b:AutoPairs')
let b:AutoPairs = g:AutoPairs
end
" buffer level map pairs keys
for [open, close] in items(g:AutoPairs)
for [open, close] in items(b:AutoPairs)
call AutoPairsMap(open)
if open != close
call AutoPairsMap(close)
end
let g:AutoPairsClosedPairs[close] = open
let b:AutoPairsClosedPairs[close] = open
endfor
" Still use <buffer> level mapping for <BS> <SPACE>
@ -355,10 +402,11 @@ function! s:ExpandMap(map)
return map
endfunction
function! AutoPairsForceInit()
function! AutoPairsTryInit()
if exists('b:autopairs_loaded')
return
end
" for auto-pairs starts with 'a', so the priority is higher than supertab and vim-endwise
"
" vim-endwise doesn't support <Plug>AutoPairsReturn
@ -404,4 +452,4 @@ inoremap <silent> <SID>AutoPairsReturn <C-R>=AutoPairsReturn()<CR>
imap <script> <Plug>AutoPairsReturn <SID>AutoPairsReturn
au BufEnter * :call AutoPairsForceInit()
au BufEnter * :call AutoPairsTryInit()