Skip to content

Commit

Permalink
Support matchpairs
Browse files Browse the repository at this point in the history
  • Loading branch information
Boolean263 committed Feb 9, 2022
1 parent baf89ad commit a837c05
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions plugin/surround.vim
Expand Up @@ -130,6 +130,7 @@ function! s:wrap(string,char,type,removed,special)
let s:input = ""
let type = a:type
let linemode = type ==# 'V' ? 1 : 0
let mp = split(&matchpairs, '[:,]') " assumes it's well-formed
let before = ""
let after = ""
if type ==# "V"
Expand All @@ -144,6 +145,7 @@ function! s:wrap(string,char,type,removed,special)
let extraspace = ' '
endif
let idx = stridx(pairs,newchar)
let mpidx = index(mp, newchar)
if newchar == ' '
let before = ''
let after = ''
Expand Down Expand Up @@ -241,6 +243,11 @@ function! s:wrap(string,char,type,removed,special)
let idx = idx / 3 * 3
let before = strpart(pairs,idx+1,1) . spc
let after = spc . strpart(pairs,idx+2,1)
elseif mpidx >= 0
let spc = (mpidx % 2) == 1 ? " " : ""
let mpidx = mpidx / 2 * 2
let before = mp[mpidx] . spc
let after = spc . mp[mpidx+1]
elseif newchar == "\<C-[>" || newchar == "\<C-]>"
let before = "{\n\t"
let after = "\n}"
Expand Down Expand Up @@ -391,6 +398,8 @@ function! s:dosurround(...) " {{{1
return s:beep()
endif
endif
let mp = split(&matchpairs, '[:,]') " assumes it's well-formed
let mpidx = index(mp, char)
let cb_save = &clipboard
set clipboard-=unnamed clipboard-=unnamedplus
let append = ""
Expand All @@ -406,6 +415,13 @@ function! s:dosurround(...) " {{{1
exe 'norm! l'
endif
exe 'norm! dt'.char
elseif mpidx >= 0
let mpidx = mpidx / 2 * 2
if getline('.')[col('.')-1] == mp[mpidx]
exe 'norm! l'
endif
exe 'norm! T'.mp[mpidx]
exe 'norm! dt'.mp[mpidx+1]
else
exe 'norm! d'.strcount.'i'.char
endif
Expand Down Expand Up @@ -433,6 +449,9 @@ function! s:dosurround(...) " {{{1
elseif char =~# '[[:punct:][:space:]]' && char !~# '[][(){}<>]'
exe 'norm! F'.char
exe 'norm! df'.char
elseif mpidx >= 0
exe 'norm! F'.mp[mpidx]
exe 'norm! df'.mp[mpidx+1]
else
" One character backwards
call search('\m.', 'bW')
Expand Down

0 comments on commit a837c05

Please sign in to comment.