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 "\"