From 86f6aca95636d5460c97471f302dc1fa41b57c9f Mon Sep 17 00:00:00 2001 From: John Whitley Date: Fri, 24 May 2013 22:18:35 -0700 Subject: [PATCH 1/2] Add support for 'cS' per issue 48 This adds support for a cS command that puts the contents of the wrapped region on their own line, analogous to yS. This change includes repeat support. --- plugin/surround.vim | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugin/surround.vim b/plugin/surround.vim index 148a5c9..e283ed2 100644 --- a/plugin/surround.vim +++ b/plugin/surround.vim @@ -441,7 +441,8 @@ function! s:dosurround(...) " {{{1 endif call setreg('"',keeper,regtype) if newchar != "" - call s:wrapreg('"',newchar) + let special = a:0 > 2 ? a:3 : 0 + call s:wrapreg('"',newchar, special) endif silent exe 'norm! ""'.pcmd.'`[' if removed =~ '\n' || okeeper =~ '\n' || getreg('"') =~ '\n' @@ -456,11 +457,11 @@ function! s:dosurround(...) " {{{1 if newchar == "" silent! call repeat#set("\Dsurround".char,scount) else - silent! call repeat#set("\Csurround".char.newchar.s:input,scount) + silent! call repeat#set("\C".(a:0 > 2 && a:3 ? "S" : "s")."urround".char.newchar.s:inpur,scount) endif endfunction " }}}1 -function! s:changesurround() " {{{1 +function! s:changesurround(...) " {{{1 let a = s:inputtarget() if a == "" return s:beep() @@ -469,7 +470,7 @@ function! s:changesurround() " {{{1 if b == "" return s:beep() endif - call s:dosurround(a,b) + call s:dosurround(a,b,a:0 && a:1) endfunction " }}}1 function! s:opfunc(type,...) " {{{1 @@ -558,6 +559,7 @@ endfunction " }}}1 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 @@ -571,6 +573,7 @@ inoremap ISurround =insert(1) if !exists("g:surround_no_mappings") || ! g:surround_no_mappings nmap ds Dsurround nmap cs Csurround + nmap cS CSurround nmap ys Ysurround nmap yS YSurround nmap yss Yssurround From 5211890344a1350f4033450ad5de877022da570f Mon Sep 17 00:00:00 2001 From: John Whitley Date: Fri, 24 May 2013 22:32:11 -0700 Subject: [PATCH 2/2] Update documentation for 'cS' --- doc/surround.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/surround.txt b/doc/surround.txt index 30a642a..41943e7 100644 --- a/doc/surround.txt +++ b/doc/surround.txt @@ -39,8 +39,9 @@ easiest to understand with some examples:
Yo!*
dst Yo! Change surroundings is *cs* . It takes two arguments, a target like with -|ds|, and a replacement. Details about the second argument can be found -below in |surround-replacements|. Once again, examples are in order. +|ds|, and a replacement. *cS* changes surroundings, placing the surrounded +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 ~ "Hello *world!" cs"' 'Hello world!'