Merge pull request #96 from jwhitley/john/cS

Add support for 'cS' per issue 48
This commit is contained in:
Tim Pope 2015-02-03 12:39:09 -06:00
commit 6e0a168a97
2 changed files with 10 additions and 6 deletions

View File

@ -39,8 +39,9 @@ easiest to understand with some examples:
<div>Yo!*</div> dst Yo! <div>Yo!*</div> dst Yo!
Change surroundings is *cs* . It takes two arguments, a target like with Change surroundings is *cs* . It takes two arguments, a target like with
|ds|, and a replacement. Details about the second argument can be found |ds|, and a replacement. *cS* changes surroundings, placing the surrounded
below in |surround-replacements|. Once again, examples are in order. text on its own line(s) like |yS|. Details about the second argument can be
found below in |surround-replacements|. Once again, examples are in order.
Old text Command New text ~ Old text Command New text ~
"Hello *world!" cs"' 'Hello world!' "Hello *world!" cs"' 'Hello world!'

View File

@ -441,7 +441,8 @@ function! s:dosurround(...) " {{{1
endif endif
call setreg('"',keeper,regtype) call setreg('"',keeper,regtype)
if newchar != "" if newchar != ""
call s:wrapreg('"',newchar) let special = a:0 > 2 ? a:3 : 0
call s:wrapreg('"',newchar, special)
endif endif
silent exe 'norm! ""'.pcmd.'`[' silent exe 'norm! ""'.pcmd.'`['
if removed =~ '\n' || okeeper =~ '\n' || getreg('"') =~ '\n' if removed =~ '\n' || okeeper =~ '\n' || getreg('"') =~ '\n'
@ -456,11 +457,11 @@ function! s:dosurround(...) " {{{1
if newchar == "" if newchar == ""
silent! call repeat#set("\<Plug>Dsurround".char,scount) silent! call repeat#set("\<Plug>Dsurround".char,scount)
else else
silent! call repeat#set("\<Plug>Csurround".char.newchar.s:input,scount) silent! call repeat#set("\<Plug>C".(a:0 > 2 && a:3 ? "S" : "s")."urround".char.newchar.s:inpur,scount)
endif endif
endfunction " }}}1 endfunction " }}}1
function! s:changesurround() " {{{1 function! s:changesurround(...) " {{{1
let a = s:inputtarget() let a = s:inputtarget()
if a == "" if a == ""
return s:beep() return s:beep()
@ -469,7 +470,7 @@ function! s:changesurround() " {{{1
if b == "" if b == ""
return s:beep() return s:beep()
endif endif
call s:dosurround(a,b) call s:dosurround(a,b,a:0 && a:1)
endfunction " }}}1 endfunction " }}}1
function! s:opfunc(type,...) " {{{1 function! s:opfunc(type,...) " {{{1
@ -558,6 +559,7 @@ endfunction " }}}1
nnoremap <silent> <Plug>SurroundRepeat . nnoremap <silent> <Plug>SurroundRepeat .
nnoremap <silent> <Plug>Dsurround :<C-U>call <SID>dosurround(<SID>inputtarget())<CR> nnoremap <silent> <Plug>Dsurround :<C-U>call <SID>dosurround(<SID>inputtarget())<CR>
nnoremap <silent> <Plug>Csurround :<C-U>call <SID>changesurround()<CR> nnoremap <silent> <Plug>Csurround :<C-U>call <SID>changesurround()<CR>
nnoremap <silent> <Plug>CSurround :<C-U>call <SID>changesurround(1)<CR>
nnoremap <silent> <Plug>Yssurround :<C-U>call <SID>opfunc(v:count1)<CR> nnoremap <silent> <Plug>Yssurround :<C-U>call <SID>opfunc(v:count1)<CR>
nnoremap <silent> <Plug>YSsurround :<C-U>call <SID>opfunc2(v:count1)<CR> nnoremap <silent> <Plug>YSsurround :<C-U>call <SID>opfunc2(v:count1)<CR>
" <C-U> discards the numerical argument but there's not much we can do with it " <C-U> discards the numerical argument but there's not much we can do with it
@ -571,6 +573,7 @@ inoremap <silent> <Plug>ISurround <C-R>=<SID>insert(1)<CR>
if !exists("g:surround_no_mappings") || ! g:surround_no_mappings if !exists("g:surround_no_mappings") || ! g:surround_no_mappings
nmap ds <Plug>Dsurround nmap ds <Plug>Dsurround
nmap cs <Plug>Csurround nmap cs <Plug>Csurround
nmap cS <Plug>CSurround
nmap ys <Plug>Ysurround nmap ys <Plug>Ysurround
nmap yS <Plug>YSurround nmap yS <Plug>YSurround
nmap yss <Plug>Yssurround nmap yss <Plug>Yssurround