From 9758a447cfb0c06cc8f467d2ddf6a34b8d9dc179 Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Tue, 9 Oct 2012 15:00:34 +0800 Subject: [PATCH] =?UTF-8?q?fixes=20#23:=20Support=20typographer's=20quote?= =?UTF-8?q?=20pairs,=20such=20as=20=E2=80=98,=20=E2=80=99,=20=E2=80=9C,=20?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/auto-pairs.vim | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index 56930bd..0a3e598 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -72,9 +72,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 @@ -151,9 +154,11 @@ endfunction function! AutoPairsDelete() 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 "\"