From 83e22c7e3b936e423855d9d5635aa1c3db8fa4e2 Mon Sep 17 00:00:00 2001 From: xluffy Date: Thu, 16 Jun 2016 08:29:07 +0700 Subject: [PATCH 01/16] Update install auto-pair - Manual install with copy plugin file - Install with Pathogen - Install with Vundle plugin manager --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 72bde89..4625589 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,13 @@ Insert or delete brackets, parens, quotes in pair. Installation ------------ -copy plugin/auto-pairs.vim to ~/.vim/plugin -or if you are using `pathogen`: - -```git clone git://github.com/jiangmiao/auto-pairs.git ~/.vim/bundle/auto-pairs``` +* Manual + * Copy `plugin/auto-pairs.vim` to `~/.vim/plugin` +* [Pathogen](https://github.com/tpope/vim-pathogen) + * `git clone git://github.com/jiangmiao/auto-pairs.git ~/.vim/bundle/auto-pairs` +* [Vundle](https://github.com/VundleVim/Vundle.vim) + * `Plugin 'jiangmiao/auto-pairs'` Features -------- From 3c290d9308c1b651c588865c3741a12654ae640e Mon Sep 17 00:00:00 2001 From: Ruslan Kiyanchuk Date: Tue, 18 Sep 2018 17:42:41 -0700 Subject: [PATCH 02/16] Spell fix Remove duplicated word. --- doc/AutoPairs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/AutoPairs.txt b/doc/AutoPairs.txt index 49ff549..afe589e 100644 --- a/doc/AutoPairs.txt +++ b/doc/AutoPairs.txt @@ -178,7 +178,7 @@ System Shortcuts: : BackInsert (|g:AutoPairsShortcutBackInsert|) - To rebind keys , or or in case of conflicts conflicts with + To rebind keys , or or in case of conflicts with another keys: let g:AutoPairsShortcutToggle = '' From cf921dadceae27d05ae05543342af23e3b6955e5 Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Sat, 12 Jan 2019 15:58:06 +0100 Subject: [PATCH 03/16] Fix breaking of keymap behavior --- plugin/auto-pairs.vim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index b2a9af7..b062ba8 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -501,6 +501,20 @@ function! AutoPairsInit() execute 'noremap ' . g:AutoPairsShortcutJump. ' :call AutoPairsJump()' end + if &keymap != '' + let l:imsearch = &imsearch + let l:iminsert = &iminsert + let l:imdisable = &imdisable + execute 'setlocal keymap=' . &keymap + execute 'setlocal imsearch=' . l:imsearch + execute 'setlocal iminsert=' . l:iminsert + if l:imdisable + execute 'setlocal imdisable' + else + execute 'setlocal noimdisable' + end + end + endfunction function! s:ExpandMap(map) From 4ec359716a48fe0953f38208e45063bdc5e551d6 Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Tue, 15 Jan 2019 04:18:06 +0800 Subject: [PATCH 04/16] Bump version 1.3.4 --- plugin/auto-pairs.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index b062ba8..93a4ed3 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -1,8 +1,8 @@ " Insert or delete brackets, parens, quotes in pairs. " Maintainer: JiangMiao " Contributor: camthompson -" Last Change: 2017-06-17 -" Version: 1.3.3 +" Last Change: 2019-01-15 +" Version: 1.3.4 " Homepage: http://www.vim.org/scripts/script.php?script_id=3599 " Repository: https://github.com/jiangmiao/auto-pairs " License: MIT From 738d1f18a8cc6b3f8e0597304e0b2bce7c107dce Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Tue, 15 Jan 2019 04:21:48 +0800 Subject: [PATCH 05/16] Support multibytes pairs --- plugin/auto-pairs.vim | 514 +++++++++++++++++------------------------- 1 file changed, 211 insertions(+), 303 deletions(-) diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index 93a4ed3..bfa072c 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -16,10 +16,6 @@ if !exists('g:AutoPairs') let g:AutoPairs = {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`'} end -if !exists('g:AutoPairsParens') - let g:AutoPairsParens = {'(':')', '[':']', '{':'}'} -end - if !exists('g:AutoPairsMapBS') let g:AutoPairsMapBS = 1 end @@ -95,263 +91,226 @@ let s:Right = s:Go."\" let g:AutoPairsClosedPairs = {} -function! AutoPairsInsert(key) - if !b:autopairs_enabled - return a:key - end +" unicode len +func! s:ulen(s) + return len(split(a:s, '\zs')) +endf +func! s:left(s) + return repeat(s:Left, s:ulen(a:s)) +endf + +func! s:right(s) + return repeat(s:Right, s:ulen(a:s)) +endf + +func! s:delete(s) + return repeat("\", s:ulen(a:s)) +endf + +func! s:backspace(s) + return repeat("\", s:ulen(a:s)) +endf + +func! s:getline() let line = getline('.') let pos = col('.') - 1 let before = strpart(line, 0, pos) let after = strpart(line, pos) - let next_chars = split(after, '\zs') - let current_char = get(next_chars, 0, '') - let next_char = get(next_chars, 1, '') - let prev_chars = split(before, '\zs') - let prev_char = get(prev_chars, -1, '') - - let eol = 0 - if col('$') - col('.') <= 1 - let eol = 1 - end - - " Ignore auto close if prev character is \ - if prev_char == '\' - return a:key - end - - " The key is difference open-pair, then it means only for ) ] } by default - 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 - if current_char == a:key - return s:Right - end - - if !g:AutoPairsFlyMode - " Skip the character if next character is space - if current_char == ' ' && next_char == a:key - return s:Right.s:Right - end - - " Skip the character if closed pair is next character - if current_char == '' - if g:AutoPairsMultilineClose - let next_lineno = line('.')+1 - let next_line = getline(nextnonblank(next_lineno)) - let next_char = matchstr(next_line, '\s*\zs.') - else - let next_char = matchstr(line, '\s*\zs.') - end - if next_char == a:key - return "\e^a" - endif - endif - endif - - " Fly Mode, and the key is closed-pairs, search closed-pair and jump - if g:AutoPairsFlyMode && has_key(b:AutoPairsClosedPairs, a:key) - let n = stridx(after, a:key) - if n != -1 - return repeat(s:Right, n+1) - end - if search(a:key, 'W') - " force break the '.' when jump to different line - return "\" - endif - endif - - " Insert directly if the key is not an open key - return a:key - end - - let open = a:key - let close = b:AutoPairs[open] - - if current_char == close && open == close - return s:Right - end - - " Ignore auto close ' if follows a word - " MUST after closed check. 'hello|' - if a:key == "'" && prev_char =~ '\v\w' - return a:key - end - - " support for ''' ``` and """ - if open == close - " The key must be ' " ` - let pprev_char = line[col('.')-3] - if pprev_char == open && prev_char == open - " Double pair found - return repeat(a:key, 4) . repeat(s:Left, 3) - end - end - - let quotes_num = 0 - " Ignore comment line for vim file - if &filetype == 'vim' && a:key == '"' - if before =~ '^\s*$' - return a:key - end - if before =~ '^\s*"' - let quotes_num = -1 - end - end - - " Keep quote number is odd. - " Because quotes should be matched in the same line in most of situation - if g:AutoPairsSmartQuotes && open == close - " Remove \\ \" \' - let cleaned_line = substitute(line, '\v(\\.)', '', 'g') - let n = quotes_num - let pos = 0 - while 1 - let pos = stridx(cleaned_line, open, pos) - if pos == -1 + if g:AutoPairsMultilineClose + let n = line('$') + let i = line('.')+1 + while i <= n + let line = getline(i) + let after = after.' '.line + if !(line =~ '\v^\s*$') break end - let n = n + 1 - let pos = pos + 1 + let i = i+1 endwhile - if n % 2 == 1 - return a:key + end + return [before, after] +endf + +" add or delete pairs base on g:AutoPairs +" AutoPairsDefine(addPairs:dict[, removeOpenPairList:list]) +" +" eg: +" au FileType html let b:AutoPairs = AutoPairsDefine({''}, ['{']) +" add pair and remove '{' for html file +func! AutoPairsDefine(pairs, ...) + let r = copy(g:AutoPairs) + for [open, close] in items(a:pairs) + let r[open] = close + endfor + if a:0 > 1 + for open in a:1 + unlet r[open] + endfor + end + return r +endf + +func! AutoPairsInsert(key) + if !b:autopairs_enabled + return a:key + end + + let b:autopairs_saved_pair = [a:key, getpos('.')] + + let [before, after] = s:getline() + + " Ignore auto close if prev character is \ + if before[-1:-1] == '\' + return a:key + end + + " check close pairs + for [open, close] in b:AutoPairsList + if close[0] == a:key + let m = matchlist(after, '\v^\s*(\V'.close.'\v)') + if len(m) > 0 + " skip close pair + call search(m[1], 'We') + return "\" + end + end + endfor + + " check open pairs + let text=before.a:key + for [open, close] in b:AutoPairsList + let m = matchstr(text, '\V'.open.'\v$') + if m != '' + " process the open pair + + " remove inserted pair + " if the pairs include < > and + " when + " eg: if the pairs include < > and " when " when , <% %>, """ """ + See multibyte pairs section for details * Fly Mode @@ -298,6 +284,88 @@ TroubleShooting Because AutoPairs uses Meta(Alt) key as shortcut, it is conflict with some Swedish character such as å. To fix the issue, you need remap or disable the related shortcut. +Multibyte Pairs +--------------- + + The default pairs is {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`'} + You could also define multibyte pairs such as , <% %> and so on + + Here are some examples + +* General usage + + au FileType php let b:AutoPairs = AutoPairsDefine({'', ''}) + + the first key of closed pair ? will be mapped + + pairs: '', '' + input: + + input: + + input: he (press at|) + output: he| + + input: (press ? at|) + output: | + + pair: '[[':']]' + input: [[|]] (press
) + output: | ([[ and ]] will be deleted the [['s priority is higher than [ for it's longer) + +* Modifier + + The text after // in close pair is modifiers + + n - do not map the first charactor of closed pair + + for 'begin' 'end' pair, e is a charactor, if map e to jump will be annoy, so use modifier 'n' to skip key map + + au FileType ruby let b:AutoPairs = AutoPairsDefine({'begin': 'end//n]'}) + + + input: begin + output: begin|end + + input: begin|end (press
on |) + output: | + + input: begin|end (press e on |) + output: begineend (will not jump for e is not mapped) + +* Advanced usage + + au FileType rust let b:AutoPairs = AutoPairsDefine({'\w\zs<': '>'}) + + if press < after a word will generate the pair + + when use regexp MUST use \zs to prevent catching + if use '\w<' without \zs, for text hello<|> press on | will output 'hell', the 'o' has been deleted + + pair: '\w\zs<': '>' + input: h < + output: h < + + input: h< + output: h<|> + + input: h<|> press
+ output: h| + + pair: '\ws<': '>' (WRONG pair which missed \zs) + input: h<|> press
+ output: | (charactor 'h' is deleted) + + + the 'begin' 'end' pair write in + + au FileType ruby let b:AutoPairs = AutoPairsDefine({'\v(^|[^\w])\zsbegin': 'end//n'}) + + will be better, only auto pair when at start of line or follow non-word text + + Known Issues ----------------------- Breaks '.' - [issue #3](https://github.com/jiangmiao/auto-pairs/issues/3) From 4d5060c80c1e78e6670e2092c44cee4dcb04cb04 Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Tue, 15 Jan 2019 17:17:06 +0800 Subject: [PATCH 09/16] Add wild closed pair --- README.md | 22 ++++++++++++++-------- plugin/auto-pairs.vim | 6 +++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fda583f..667e9ed 100644 --- a/README.md +++ b/README.md @@ -57,13 +57,6 @@ Features * Fast Wrap - input: |'hello' (press ( at |) - output: ('hello') - - wrap string, only support c style string - input: |'h\\el\'lo' (press ( at |) - output ('h\\ello\'') - input: |[foo, bar()] (press ( at |) output: ([foo, bar()]) @@ -250,6 +243,13 @@ Options Map to move character under the cursor to the pair. +* g:AutoPairsWildClosedPair + + Default: ']' + + Jump over following closed pair + for pair {'begin': 'end//n]'}, e is not mapped, use wild closed pair ] to jump over 'end' + Buffer Level Pairs Setting -------------------------- @@ -290,7 +290,13 @@ Multibyte Pairs The default pairs is {'(':')', '[':']', '{':'}',"'":"'",'"':'"', '`':'`'} You could also define multibyte pairs such as , <% %> and so on - Here are some examples +* Function AutoPairsDefine(addPairs:dict[, removeOpenPairList:list]) + + add or delete pairs base on g:AutoPairs + + eg: + au FileType html let b:AutoPairs = AutoPairsDefine({''}, ['{']) + add pair and remove '{' for html file * General usage diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index 2cb6340..ae79b32 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -2,7 +2,7 @@ " Maintainer: JiangMiao " Contributor: camthompson " Last Change: 2019-01-15 -" Version: 1.3.4 +" Version: 2.0.0 " Homepage: http://www.vim.org/scripts/script.php?script_id=3599 " Repository: https://github.com/jiangmiao/auto-pairs " License: MIT @@ -185,8 +185,8 @@ func! AutoPairsInsert(key) " check close pairs for [open, close] in b:AutoPairsList - if close[0] == a:key - let m = s:matchbegin(after, '\v\s*\V'.close) + if a:key == g:AutoPairsWildClosedPair || close[0] == a:key + let m = s:matchbegin(after, '\v\s*\zs\V'.close) if len(m) > 0 " skip close pair call search(m[1], 'We') From 177664ab1aa9b12e50134a4b004ddb5e694cd115 Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Tue, 15 Jan 2019 18:40:51 +0800 Subject: [PATCH 10/16] Update README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 667e9ed..944201a 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Insert or delete brackets, parens, quotes in pair. Installation ------------ + copy plugin/auto-pairs.vim to ~/.vim/plugin or if you are using `pathogen`: @@ -249,6 +250,7 @@ Options Jump over following closed pair for pair {'begin': 'end//n]'}, e is not mapped, use wild closed pair ] to jump over 'end' + use to back insert ] after jumping Buffer Level Pairs Setting -------------------------- @@ -259,6 +261,7 @@ eg: " When the filetype is FILETYPE then make AutoPairs only match for parenthesis au Filetype FILETYPE let b:AutoPairs = {"(": ")"} + au FileType php let b:AutoPairs = AutoPairsDefine({'', ''}) TroubleShooting --------------- @@ -298,6 +301,8 @@ Multibyte Pairs au FileType html let b:AutoPairs = AutoPairsDefine({''}, ['{']) add pair and remove '{' for html file + the pair implict start with \V, so if want to match start of line ^ should be write in \^ vim comment {'\^"': ''} + * General usage au FileType php let b:AutoPairs = AutoPairsDefine({'', ''}) From bec90a4076cd559e290b61abda8073800f06c720 Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Tue, 15 Jan 2019 18:52:47 +0800 Subject: [PATCH 11/16] Update README --- README.md | 92 +++++++++++++++++++++++++++---------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index e1fe0bb..41b351b 100644 --- a/README.md +++ b/README.md @@ -296,86 +296,86 @@ Multibyte Pairs * Function AutoPairsDefine(addPairs:dict[, removeOpenPairList:list]) - add or delete pairs base on g:AutoPairs + add or delete pairs base on g:AutoPairs - eg: - au FileType html let b:AutoPairs = AutoPairsDefine({''}, ['{']) - add pair and remove '{' for html file + eg: + au FileType html let b:AutoPairs = AutoPairsDefine({''}, ['{']) + add pair and remove '{' for html file - the pair implict start with \V, so if want to match start of line ^ should be write in \^ vim comment {'\^"': ''} + the pair implict start with \V, so if want to match start of line ^ should be write in \^ vim comment {'\^"': ''} * General usage - au FileType php let b:AutoPairs = AutoPairsDefine({'', ''}) + au FileType php let b:AutoPairs = AutoPairsDefine({'', ''}) - the first key of closed pair ? will be mapped + the first key of closed pair ? will be mapped - pairs: '', '' - input: + pairs: '', '' + input: - input: + input: - input: he (press at|) - output: he| + input: he (press at|) + output: he| - input: (press ? at|) - output: | + input: (press ? at|) + output: | - pair: '[[':']]' - input: [[|]] (press
) - output: | ([[ and ]] will be deleted the [['s priority is higher than [ for it's longer) + pair: '[[':']]' + input: [[|]] (press
) + output: | ([[ and ]] will be deleted the [['s priority is higher than [ for it's longer) * Modifier - The text after // in close pair is modifiers + The text after // in close pair is modifiers - n - do not map the first charactor of closed pair + n - do not map the first charactor of closed pair - for 'begin' 'end' pair, e is a charactor, if map e to jump will be annoy, so use modifier 'n' to skip key map + for 'begin' 'end' pair, e is a charactor, if map e to jump will be annoy, so use modifier 'n' to skip key map - au FileType ruby let b:AutoPairs = AutoPairsDefine({'begin': 'end//n]'}) + au FileType ruby let b:AutoPairs = AutoPairsDefine({'begin': 'end//n]'}) - input: begin - output: begin|end + input: begin + output: begin|end - input: begin|end (press
on |) - output: | + input: begin|end (press
on |) + output: | - input: begin|end (press e on |) - output: begineend (will not jump for e is not mapped) + input: begin|end (press e on |) + output: begineend (will not jump for e is not mapped) * Advanced usage - au FileType rust let b:AutoPairs = AutoPairsDefine({'\w\zs<': '>'}) + au FileType rust let b:AutoPairs = AutoPairsDefine({'\w\zs<': '>'}) - if press < after a word will generate the pair + if press < after a word will generate the pair - when use regexp MUST use \zs to prevent catching - if use '\w<' without \zs, for text hello<|> press on | will output 'hell', the 'o' has been deleted + when use regexp MUST use \zs to prevent catching + if use '\w<' without \zs, for text hello<|> press on | will output 'hell', the 'o' has been deleted - pair: '\w\zs<': '>' - input: h < - output: h < + pair: '\w\zs<': '>' + input: h < + output: h < - input: h< - output: h<|> + input: h< + output: h<|> - input: h<|> press
- output: h| + input: h<|> press
+ output: h| - pair: '\ws<': '>' (WRONG pair which missed \zs) - input: h<|> press
- output: | (charactor 'h' is deleted) + pair: '\ws<': '>' (WRONG pair which missed \zs) + input: h<|> press
+ output: | (charactor 'h' is deleted) - the 'begin' 'end' pair write in + the 'begin' 'end' pair write in - au FileType ruby let b:AutoPairs = AutoPairsDefine({'\v(^|[^\w])\zsbegin': 'end//n'}) + au FileType ruby let b:AutoPairs = AutoPairsDefine({'\v(^|[^\w])\zsbegin': 'end//n'}) - will be better, only auto pair when at start of line or follow non-word text + will be better, only auto pair when at start of line or follow non-word text Known Issues From 3c7fde2643f1c611c15cb9c30e124d49dca1a4ef Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Tue, 15 Jan 2019 19:08:18 +0800 Subject: [PATCH 12/16] Update README --- README.md | 57 +++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 41b351b..3aa8cb8 100644 --- a/README.md +++ b/README.md @@ -84,11 +84,6 @@ Features }| -* Multibyte Pairs - - Support any multibyte pairs such as , <% %>, """ """ - See multibyte pairs section for details - * Fly Mode input: if(a[3) @@ -118,6 +113,11 @@ Features See Fly Mode section for details +* Multibyte Pairs + + Support any multibyte pairs such as , <% %>, """ """ + See multibyte pairs section for details + Fly Mode -------- Fly Mode will always force closed-pair jumping instead of inserting. only for ")", "}", "]" @@ -264,30 +264,6 @@ eg: au Filetype FILETYPE let b:AutoPairs = {"(": ")"} au FileType php let b:AutoPairs = AutoPairsDefine({'', ''}) -TroubleShooting ---------------- - The script will remap keys ([{'"}]) , - If auto pairs cannot work, use :imap ( to check if the map is corrected. - The correct map should be =AutoPairsInsert("\(") - Or the plugin conflict with some other plugins. - use command :call AutoPairsInit() to remap the keys. - - -* How to insert parens purely - - There are 3 ways - - 1. use Ctrl-V ) to insert paren without trigger the plugin. - - 2. use Alt-P to turn off the plugin. - - 3. use DEL or x to delete the character insert by plugin. - -* Swedish Character Conflict - - Because AutoPairs uses Meta(Alt) key as shortcut, it is conflict with some Swedish character such as å. - To fix the issue, you need remap or disable the related shortcut. - Multibyte Pairs --------------- @@ -377,6 +353,29 @@ Multibyte Pairs will be better, only auto pair when at start of line or follow non-word text +TroubleShooting +--------------- + The script will remap keys ([{'"}]) , + If auto pairs cannot work, use :imap ( to check if the map is corrected. + The correct map should be =AutoPairsInsert("\(") + Or the plugin conflict with some other plugins. + use command :call AutoPairsInit() to remap the keys. + + +* How to insert parens purely + + There are 3 ways + + 1. use Ctrl-V ) to insert paren without trigger the plugin. + + 2. use Alt-P to turn off the plugin. + + 3. use DEL or x to delete the character insert by plugin. + +* Swedish Character Conflict + + Because AutoPairs uses Meta(Alt) key as shortcut, it is conflict with some Swedish character such as å. + To fix the issue, you need remap or disable the related shortcut. Known Issues ----------------------- From ea2fd8a2deb77a33dd8849c7fa7383b84317b684 Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Tue, 15 Jan 2019 19:10:52 +0800 Subject: [PATCH 13/16] Update README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3aa8cb8..c80af60 100644 --- a/README.md +++ b/README.md @@ -300,7 +300,7 @@ Multibyte Pairs output: | pair: '[[':']]' - input: [[|]] (press
) + input: [[|]] (press ) output: | ([[ and ]] will be deleted the [['s priority is higher than [ for it's longer) * Modifier @@ -317,7 +317,7 @@ Multibyte Pairs input: begin output: begin|end - input: begin|end (press
on |) + input: begin|end (press on |) output: | input: begin|end (press e on |) @@ -339,11 +339,11 @@ Multibyte Pairs input: h< output: h<|> - input: h<|> press
+ input: h<|> press output: h| pair: '\ws<': '>' (WRONG pair which missed \zs) - input: h<|> press
+ input: h<|> press output: | (charactor 'h' is deleted) From 423ee192c727bc27e272a28fbb3f951a9548a765 Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Tue, 15 Jan 2019 19:38:21 +0800 Subject: [PATCH 14/16] Prevent jumping multi line if open pair equals close pair --- README.md | 2 +- plugin/auto-pairs.vim | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c80af60..862c9b9 100644 --- a/README.md +++ b/README.md @@ -342,7 +342,7 @@ Multibyte Pairs input: h<|> press output: h| - pair: '\ws<': '>' (WRONG pair which missed \zs) + pair: '\w<': '>' (WRONG pair which missed \zs) input: h<|> press output: | (charactor 'h' is deleted) diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index 6509c31..a79dd4e 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -114,12 +114,12 @@ func! s:backspace(s) return repeat("\", s:ulen(a:s)) endf -func! s:getline() +func! s:getline(...) let line = getline('.') let pos = col('.') - 1 let before = strpart(line, 0, pos) let after = strpart(line, pos) - if g:AutoPairsMultilineClose + if a:0 == 0 && g:AutoPairsMultilineClose let n = line('$') let i = line('.')+1 while i <= n @@ -186,6 +186,9 @@ func! AutoPairsInsert(key) " check close pairs for [open, close] in b:AutoPairsList if a:key == g:AutoPairsWildClosedPair || close[0] == a:key + if open == close + let [before, after] = s:getline(0) + end let m = s:matchbegin(after, '\v\s*\zs\V'.close) if len(m) > 0 " skip close pair From 7d721d261f18127ae6fb1220ab226d2593db2e7a Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Tue, 15 Jan 2019 21:33:19 +0800 Subject: [PATCH 15/16] Indent line when return --- plugin/auto-pairs.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index a79dd4e..e791c42 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -336,7 +336,8 @@ func! AutoPairsReturn() let after = getline('.') let cmd = '' for [open, close] in b:AutoPairsList - if before =~ '\V'.open.'\v\s*$' && after =~ '^\s*\V'.close + " before =~ '\V'.open.'\v\s*$' && + if after =~ '^\s*\V'.close if g:AutoPairsCenterLine && winline() * 3 >= winheight(0) * 2 " Recenter before adding new line to avoid replacing line content let cmd = "zz" From 38d53d4df05ddec3a75fa801c4ba8600b8fcd4a9 Mon Sep 17 00:00:00 2001 From: Miao Jiang Date: Tue, 15 Jan 2019 22:26:37 +0800 Subject: [PATCH 16/16] Close empty pairs smartly --- plugin/auto-pairs.vim | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/plugin/auto-pairs.vim b/plugin/auto-pairs.vim index e791c42..d329bb5 100644 --- a/plugin/auto-pairs.vim +++ b/plugin/auto-pairs.vim @@ -114,11 +114,12 @@ func! s:backspace(s) return repeat("\", s:ulen(a:s)) endf -func! s:getline(...) +func! s:getline() let line = getline('.') let pos = col('.') - 1 let before = strpart(line, 0, pos) let after = strpart(line, pos) + let afterline = after if a:0 == 0 && g:AutoPairsMultilineClose let n = line('$') let i = line('.')+1 @@ -131,7 +132,7 @@ func! s:getline(...) let i = i+1 endwhile end - return [before, after] + return [before, after, afterline] endf " split text to two part @@ -176,7 +177,7 @@ func! AutoPairsInsert(key) let b:autopairs_saved_pair = [a:key, getpos('.')] - let [before, after] = s:getline() + let [before, after, afterline] = s:getline() " Ignore auto close if prev character is \ if before[-1:-1] == '\' @@ -186,16 +187,20 @@ func! AutoPairsInsert(key) " check close pairs for [open, close] in b:AutoPairsList if a:key == g:AutoPairsWildClosedPair || close[0] == a:key - if open == close - let [before, after] = s:getline(0) - end - let m = s:matchbegin(after, '\v\s*\zs\V'.close) - if len(m) > 0 - " skip close pair - let c = matchstr(after, '^\V'.close) - if c != "" - return s:right(c) + " the close pair is in the same line + let m = matchstr(afterline, '^\v\s*\V'.close) + if m != '' + if before =~ '\V'.open.'\v\s*$' && m[0] =~ '\v\s' + " remove the space we inserted if the text in pairs is blank + return "\".s:right(m[1:]) else + return s:right(m) + end + end + if open != close + let m = s:matchend(after, '^\v\s*\zs\V'.close) + if len(m) > 0 + " skip close pair greedy call search(m[1], 'We') return "\" end @@ -265,7 +270,7 @@ func! AutoPairsDelete() return "\" end - let [before, after] = s:getline() + let [before, after, ig] = s:getline() for [open, close] in b:AutoPairsList let b = matchstr(before, '\V'.open.'\v\s?$') let a = matchstr(after, '^\v\s*\V'.close) @@ -288,7 +293,7 @@ endf func! AutoPairsFastWrap() let c = @" normal! x - let [before, after] = s:getline() + let [before, after, ig] = s:getline() if after[0] =~ '\v[\{\[\(\<]' normal! % normal! p @@ -301,8 +306,12 @@ func! AutoPairsFastWrap() return "" end endfor - normal! e - normal! p + if after[1:1] =~ '\v[a-zA-Z0-9_]' + normal! e + normal! p + else + normal! p + end end let @" = c return "" @@ -367,7 +376,7 @@ func! AutoPairsSpace() return "\" end - let [before, after] = s:getline() + let [before, after, ig] = s:getline() for [open, close] in b:AutoPairsList if before =~ '\V'.open.'\v$' && after =~ '^\V'.close