@@ -478,7 +478,11 @@ function! s:changesurround(...) " {{{1
478
478
call s: dosurround (a ,b ,a: 0 && a: 1 )
479
479
endfunction " }}}1
480
480
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
482
486
let char = s: inputreplacement ()
483
487
if char == " "
484
488
return s: beep ()
@@ -541,8 +545,12 @@ function! s:opfunc(type,...) " {{{1
541
545
endif
542
546
endfunction
543
547
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 )
546
554
endfunction " }}}1
547
555
548
556
function ! s: closematch (str) " {{{1
@@ -565,11 +573,10 @@ nnoremap <silent> <Plug>SurroundRepeat .
565
573
nnoremap <silent> <Plug> Dsurround :<C-U> call <SID> dosurround(<SID> inputtarget())<CR>
566
574
nnoremap <silent> <Plug> Csurround :<C-U> call <SID> changesurround()<CR>
567
575
nnoremap <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')
573
580
vnoremap <silent> <Plug> VSurround :<C-U> call <SID> opfunc(visualmode(),visualmode() ==# 'V' ? 1 : 0)<CR>
574
581
vnoremap <silent> <Plug> VgSurround :<C-U> call <SID> opfunc(visualmode(),visualmode() ==# 'V' ? 0 : 1)<CR>
575
582
inoremap <silent> <Plug> Isurround <C-R> =<SID> insert()<CR>
0 commit comments