@@ -478,7 +478,11 @@ function! s:changesurround(...) " {{{1
478478 call s: dosurround (a ,b ,a: 0 && a: 1 )
479479endfunction " }}}1
480480
481- function ! s: opfunc (type ,... ) " {{{1
481+ function ! s: opfunc (type , ... ) abort " {{{1
482+ if a: type == # ' setup'
483+ let &opfunc = matchstr (expand (' <sfile>' ), ' <SNR>\w\+$' )
484+ return ' g@'
485+ endif
482486 let char = s: inputreplacement ()
483487 if char == " "
484488 return s: beep ()
@@ -541,8 +545,12 @@ function! s:opfunc(type,...) " {{{1
541545 endif
542546endfunction
543547
544- function ! s: opfunc2 (arg)
545- call s: opfunc (a: arg ,1 )
548+ function ! s: opfunc2 (... ) abort
549+ if ! a: 0 || a: 1 == # ' setup'
550+ let &opfunc = matchstr (expand (' <sfile>' ), ' <SNR>\w\+$' )
551+ return ' g@'
552+ endif
553+ call s: opfunc (a: 1 , 1 )
546554endfunction " }}}1
547555
548556function ! s: closematch (str) " {{{1
@@ -565,11 +573,10 @@ nnoremap <silent> <Plug>SurroundRepeat .
565573nnoremap <silent> <Plug> Dsurround :<C-U> call <SID> dosurround(<SID> inputtarget())<CR>
566574nnoremap <silent> <Plug> Csurround :<C-U> call <SID> changesurround()<CR>
567575nnoremap <silent> <Plug> CSurround :<C-U> call <SID> changesurround(1)<CR>
568- nnoremap <silent> <Plug> Yssurround :<C-U> call <SID> opfunc(v:count1)<CR>
569- nnoremap <silent> <Plug> YSsurround :<C-U> call <SID> opfunc2(v:count1)<CR>
570- " <C-U> discards the numerical argument but there's not much we can do with it
571- nnoremap <silent> <Plug> Ysurround :<C-U> set opfunc=<SID> opfunc<CR> g@
572- nnoremap <silent> <Plug> YSurround :<C-U> set opfunc=<SID> opfunc2<CR> g@
576+ nnoremap <expr> <Plug> Yssurround <SID> opfunc('setup').'_'
577+ nnoremap <expr> <Plug> YSsurround <SID> opfunc2('setup').'_'
578+ nnoremap <expr> <Plug> Ysurround <SID> opfunc('setup')
579+ nnoremap <expr> <Plug> YSurround <SID> opfunc2('setup')
573580vnoremap <silent> <Plug> VSurround :<C-U> call <SID> opfunc(visualmode(),visualmode() ==# 'V' ? 1 : 0)<CR>
574581vnoremap <silent> <Plug> VgSurround :<C-U> call <SID> opfunc(visualmode(),visualmode() ==# 'V' ? 0 : 1)<CR>
575582inoremap <silent> <Plug> Isurround <C-R> =<SID> insert()<CR>
0 commit comments