From 07a90d26f34cdfba2798b17ac4749b241e552a31 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 1 Nov 2006 05:59:08 +0000 Subject: [PATCH] Cope with backslashes in blockwise visual mode --- plugin/surround.vim | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/plugin/surround.vim b/plugin/surround.vim index 596d46e..e1f302c 100644 --- a/plugin/surround.vim +++ b/plugin/surround.vim @@ -452,16 +452,13 @@ function! s:wrap(string,char,type,...) let before = substitute(before,'\n\s\+\%$','\n','') let keeper = s:fixindent(keeper,padding) endif - "if linemode || keeper =~ '\%^\s*\n' - "let before = substitute(before,' *\%$','','') - "endif - "if linemode || keeper =~ '\n\s*\%$' - "let after = substitute(after,'\%^ *','','') - "endif if type ==# 'V' let keeper = before.keeper.after elseif type =~ "^\" - let keeper = substitute(keeper."\n",'\(.\{-\}\)\n',before.'\1'.after.'\n','g') + " Really we should be iterating over the buffer + let repl = substitute(before,'[\\~]','\\&','g').'\1'.substitute(after,'[\\~]','\\&','g') + let repl = substitute(repl,'\n',' ','g') + let keeper = substitute(keeper."\n",'\(.\{-\}\)\n',repl.'\n','g') else let keeper = before.extraspace.keeper.extraspace.after endif @@ -505,29 +502,6 @@ function! s:insert(...) " {{{1 endif call search('\r','bW') return "\" - " Old implementation follows - let @@ = reg_save - "let text = s:wrap("\r",char,0) - "call inputrestore() - set paste - let nopaste = "\:set nopaste\:\gi" - if linemode - let first = substitute(matchstr(text,'.\{-\}\ze\s*\r'),'\n$','','') - let last = substitute(matchstr(text,'\r\s*\zs.*'),'^\n\s*','','') - let text = first.nopaste."\".last."\O" - elseif text =~ '\r\n' - " doesn't work with multiple newlines in second half. - let text = substitute(text,'\r\n',"\",'').nopaste."\\" - else - let len = strlen(substitute(substitute(text,'.*\r','',''),'.','.','g')) - let left = "" - while len > 0 - let len = len - 1 - let left = left . "\" - endwhile - let text = substitute(text,'\r','','') . left . nopaste - endif - return text endfunction " }}}1 function! s:reindent() " {{{1 @@ -733,6 +707,7 @@ if !exists("g:surround_no_mappings") || ! g:surround_no_mappings if !hasmapto("Isurround","i") imap Isurround endif + "Implemented internally instead "imap ISurround endif