Skip to content

Commit 4e7d573

Browse files
committed
Make ys maps atomic
Closes tpope#253
1 parent e8dca61 commit 4e7d573

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

plugin/surround.vim

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,11 @@ function! s:changesurround(...) " {{{1
478478
call s:dosurround(a,b,a:0 && a:1)
479479
endfunction " }}}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
542546
endfunction
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)
546554
endfunction " }}}1
547555

548556
function! s:closematch(str) " {{{1
@@ -565,11 +573,10 @@ nnoremap <silent> <Plug>SurroundRepeat .
565573
nnoremap <silent> <Plug>Dsurround :<C-U>call <SID>dosurround(<SID>inputtarget())<CR>
566574
nnoremap <silent> <Plug>Csurround :<C-U>call <SID>changesurround()<CR>
567575
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')
573580
vnoremap <silent> <Plug>VSurround :<C-U>call <SID>opfunc(visualmode(),visualmode() ==# 'V' ? 1 : 0)<CR>
574581
vnoremap <silent> <Plug>VgSurround :<C-U>call <SID>opfunc(visualmode(),visualmode() ==# 'V' ? 0 : 1)<CR>
575582
inoremap <silent> <Plug>Isurround <C-R>=<SID>insert()<CR>

0 commit comments

Comments
 (0)