From 86f6aca95636d5460c97471f302dc1fa41b57c9f Mon Sep 17 00:00:00 2001 From: John Whitley Date: Fri, 24 May 2013 22:18:35 -0700 Subject: [PATCH] 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