From 4e7d573c14ea7bc7bd87448272c1cd54ddfdbfa5 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 29 May 2018 17:37:25 -0400 Subject: [PATCH] Make ys maps atomic Closes https://github.com/tpope/vim-surround/issues/253 --- plugin/surround.vim | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/plugin/surround.vim b/plugin/surround.vim index 46f3252..a91bc30 100644 --- a/plugin/surround.vim +++ b/plugin/surround.vim @@ -478,7 +478,11 @@ function! s:changesurround(...) " {{{1 call s:dosurround(a,b,a:0 && a:1) endfunction " }}}1 -function! s:opfunc(type,...) " {{{1 +function! s:opfunc(type, ...) abort " {{{1 + if a:type ==# 'setup' + let &opfunc = matchstr(expand(''), '\w\+$') + return 'g@' + endif let char = s:inputreplacement() if char == "" return s:beep() @@ -541,8 +545,12 @@ function! s:opfunc(type,...) " {{{1 endif endfunction -function! s:opfunc2(arg) - call s:opfunc(a:arg,1) +function! s:opfunc2(...) abort + if !a:0 || a:1 ==# 'setup' + let &opfunc = matchstr(expand(''), '\w\+$') + return 'g@' + endif + call s:opfunc(a:1, 1) endfunction " }}}1 function! s:closematch(str) " {{{1 @@ -565,11 +573,10 @@ nnoremap SurroundRepeat . nnoremap Dsurround :call dosurround(inputtarget()) nnoremap Csurround :call changesurround() nnoremap CSurround :call changesurround(1) -nnoremap Yssurround :call opfunc(v:count1) -nnoremap YSsurround :call opfunc2(v:count1) -" discards the numerical argument but there's not much we can do with it -nnoremap Ysurround :set opfunc=opfuncg@ -nnoremap YSurround :set opfunc=opfunc2g@ +nnoremap Yssurround opfunc('setup').'_' +nnoremap YSsurround opfunc2('setup').'_' +nnoremap Ysurround opfunc('setup') +nnoremap YSurround opfunc2('setup') vnoremap VSurround :call opfunc(visualmode(),visualmode() ==# 'V' ? 1 : 0) vnoremap VgSurround :call opfunc(visualmode(),visualmode() ==# 'V' ? 0 : 1) inoremap Isurround =insert()