Skip to content

Commit ec1cb81

Browse files
jiangmiaovim-scripts
authored andcommitted
Version 1.2.6: Support typographer's quote pairs, such as � �, � �
1 parent 0d4c289 commit ec1cb81

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

plugin/auto-pairs.vim

Lines changed: 13 additions & 8 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-09-15
5-
" Version: 1.2.5
4+
" Last Change: 2012-10-17
5+
" Version: 1.2.6
66
" Homepage: http://www.vim.org/scripts/script.php?script_id=3599
77
" Repository: https://github.com/jiangmiao/auto-pairs
88

@@ -72,9 +72,12 @@ function! AutoPairsInsert(key)
7272
end
7373

7474
let line = getline('.')
75-
let prev_char = line[col('.')-2]
76-
let current_char = line[col('.')-1]
77-
let next_char = line[col('.')]
75+
let pos = col('.') - 1
76+
let next_chars = split(strpart(line, pos), '\zs')
77+
let current_char = get(next_chars, 0, '')
78+
let next_char = get(next_chars, 1, '')
79+
let prev_chars = split(strpart(line, 0, pos), '\zs')
80+
let prev_char = get(prev_chars, -1, '')
7881

7982
let eol = 0
8083
if col('$') - col('.') <= 1
@@ -151,9 +154,11 @@ endfunction
151154

152155
function! AutoPairsDelete()
153156
let line = getline('.')
154-
let current_char = line[col('.')-1]
155-
let prev_char = line[col('.')-2]
156-
let pprev_char = line[col('.')-3]
157+
let pos = col('.') - 1
158+
let current_char = get(split(strpart(line, pos), '\zs'), 0, '')
159+
let prev_chars = split(strpart(line, 0, pos), '\zs')
160+
let prev_char = get(prev_chars, -1, '')
161+
let pprev_char = get(prev_chars, -2, '')
157162

158163
if pprev_char == '\'
159164
return "\<BS>"

0 commit comments

Comments
 (0)