Skip to content

Commit ed01a8d

Browse files
jiangmiaovim-scripts
authored andcommitted
Version 1.2.3
compatible with neocomplcache compatible with clang_complete Improve Fast Wrap
1 parent da585a4 commit ed01a8d

File tree

2 files changed

+84
-23
lines changed

2 files changed

+84
-23
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,16 @@ Features
5353

5454
* Fast Wrap
5555

56-
input: |'hello' (press (<M-e> at|)
56+
input: |'hello' (press (<M-e> at |)
5757
output: ('hello')
5858

59+
wrap string, only support c style string
60+
input: |'h\\el\'lo' (press (<M-e> at |)
61+
output ('h\\ello\'')
62+
63+
input: |[foo, bar()] (press (<M-e> at |)
64+
output: ([foo, bar()])
65+
5966
* Quick jump to closed pair.
6067

6168
input:
@@ -227,6 +234,23 @@ TroubleShooting
227234
3. use DEL or <C-O>x to delete the character insert by plugin.
228235

229236

237+
Known Issues
238+
-----------------------
239+
There are the issues I cannot fix.
240+
241+
Compatible with Vimwiki - [issue #19](https://github.com/jiangmiao/auto-pairs/issues/19)
242+
243+
Description: When works with vimwiki `<CR>` will output `<SNR>xx_CR()`
244+
Reason: vimwiki uses `<expr>` on mapping `<CR>` that auto-pairs cannot expanding.
245+
Solution: add `let g:AutoPairsMapCR = 0` to .vimrc to disable `<CR>` mapping.
246+
247+
Breaks '.' - [issue #3](https://github.com/jiangmiao/auto-pairs/issues/3)
248+
249+
Description: After entering insert mode and inputing `[hello` then leave insert mode by `<ESC>`, press '.' will insert 'hello' instead of '[hello]'.
250+
Reason: `[` actually equals `[]\<LEFT>` and \<LEFT> will break '.'
251+
Solution: none
252+
230253
Contributors
231254
------------
232255
* [camthompson](https://github.com/camthompson)
256+

plugin/auto-pairs.vim

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
" Insert or delete brackets, parens, quotes in pairs.
22
" Maintainer: JiangMiao <jiangfriend@gmail.com>
33
" Contributor: camthompson
4-
" Last Change: 2012-05-16
5-
" Version: 1.2.2
4+
" Last Change: 2012-07-15
5+
" Version: 1.2.3
66
" Homepage: http://www.vim.org/scripts/script.php?script_id=3599
77
" Repository: https://github.com/jiangmiao/auto-pairs
88

@@ -184,34 +184,62 @@ endfunction
184184
function! AutoPairsJump()
185185
call search('["\]'')}]','W')
186186
endfunction
187+
" string_chunk cannot use standalone
188+
let s:string_chunk = '\v%(\\\_.|[^\1]|[\r\n]){-}'
189+
let s:ss_pattern = '\v''' . s:string_chunk . ''''
190+
let s:ds_pattern = '\v"' . s:string_chunk . '"'
191+
192+
func! s:RegexpQuote(str)
193+
return substitute(a:str, '\v[\[\{\(\<\>\)\}\]]', '\\&', 'g')
194+
endf
195+
196+
func! s:RegexpQuoteInSquare(str)
197+
return substitute(a:str, '\v[\[\]]', '\\&', 'g')
198+
endf
199+
200+
" Search next open or close pair
201+
func! s:FormatChunk(open, close)
202+
let open = s:RegexpQuote(a:open)
203+
let close = s:RegexpQuote(a:close)
204+
let open2 = s:RegexpQuoteInSquare(a:open)
205+
let close2 = s:RegexpQuoteInSquare(a:close)
206+
if open == close
207+
return '\v'.open.s:string_chunk.close
208+
else
209+
return '\v%(' . s:ss_pattern . '|' . s:ds_pattern . '|' . '[^'.open2.close2.']|[\r\n]' . '){-}(['.open2.close2.'])'
210+
end
211+
endf
187212

188213
" Fast wrap the word in brackets
189214
function! AutoPairsFastWrap()
190215
let line = getline('.')
191216
let current_char = line[col('.')-1]
192217
let next_char = line[col('.')]
193-
194-
" Ignore EOL
195-
if col('.') == col('$')
196-
return ''
197-
end
198-
199-
normal! x
200-
if next_char =~ '\s'
201-
call search('\S', 'W')
202-
let next_char = getline('.')[col('.')-1]
218+
let open_pair_pattern = '\v[({\[''"]'
219+
let at_end = col('.') >= col('$') - 1
220+
normal x
221+
" Skip blank
222+
if next_char =~ '\v\s' || at_end
223+
call search('\v\S', 'W')
224+
let line = getline('.')
225+
let next_char = line[col('.')-1]
203226
end
204227

205-
if has_key(g:AutoExtraPairs, next_char)
206-
let close = g:AutoExtraPairs[next_char]
207-
call search(close, 'W')
208-
return "\<RIGHT>".current_char."\<LEFT>"
209-
else
210-
if next_char =~ '\w'
211-
execute "normal! he"
228+
if has_key(g:AutoPairs, next_char)
229+
let followed_open_pair = next_char
230+
let inputed_close_pair = current_char
231+
let followed_close_pair = g:AutoPairs[next_char]
232+
if followed_close_pair != followed_open_pair
233+
" TODO replace system searchpair to skip string and nested pair.
234+
" eg: (|){"hello}world"} will transform to ({"hello})world"}
235+
call searchpair('\V'.followed_open_pair, '', '\V'.followed_close_pair, 'W')
236+
else
237+
call search(s:FormatChunk(followed_open_pair, followed_close_pair), 'We')
212238
end
213-
execute "normal! a".current_char
214-
return ""
239+
return "\<RIGHT>".inputed_close_pair."\<LEFT>"
240+
else
241+
normal e
242+
return "\<RIGHT>".current_char."\<LEFT>"
215243
end
216244
endfunction
217245

@@ -352,11 +380,20 @@ function! AutoPairsForceInit()
352380
let old_cr = s:ExpandMap(old_cr)
353381
endif
354382

383+
" compatible with clang_complete
384+
" https://github.com/jiangmiao/auto-pairs/issues/18
385+
let pattern = '<SNR>\d\+_HandlePossibleSelectionEnter()'
386+
if old_cr =~ pattern
387+
execute 'imap <expr> <script> <SID>AutoPairsClangCompleteCR ' . matchstr(old_cr, pattern)
388+
let old_cr = substitute(old_cr, pattern , '<SID>AutoPairsClangCompleteCR', '')
389+
endif
390+
355391
if old_cr !~ 'AutoPairsReturn'
356392
" generally speaking, <silent> should not be here because every plugin
357393
" has there own silent solution. but for some plugin which wasn't double silent
358394
" mapping, when maparg expand the map will lose the silent info, so <silent> always.
359-
execute 'imap <buffer> <silent> <CR> '.old_cr.'<SID>AutoPairsReturn'
395+
" use inoremap for neocomplcache
396+
execute 'inoremap <script> <buffer> <silent> <CR> '.old_cr.'<SID>AutoPairsReturn'
360397
end
361398
endif
362399
call AutoPairsInit()

0 commit comments

Comments
 (0)