diff --git a/plugin/surround.vim b/plugin/surround.vim index 55068f3..acbb480 100644 --- a/plugin/surround.vim +++ b/plugin/surround.vim @@ -126,6 +126,9 @@ endfunction function! s:inputtarget() let c = s:getchar() + if c == " " + let c = c . s:getchar() + endif if c =~ "\\|\\|\0" return "" else @@ -164,7 +167,7 @@ function! s:wrap(string,char,...) " {{{1 let linemode = a:0 ? a:1 : 0 let before = "" let after = "" - " Duplicate b's are just placeholders + " Duplicate b's are just placeholders (removed) let pairs = "b()B{}r[]a<>" let extraspace = "" if newchar =~ '^ ' @@ -178,10 +181,10 @@ function! s:wrap(string,char,...) " {{{1 elseif exists("g:surround_".char2nr(newchar)) let before = matchstr(g:surround_{char2nr(newchar)},'.*\ze\n') let after = matchstr(g:surround_{char2nr(newchar)},'\n\zs.*') - elseif newchar == "p" + elseif newchar ==# "p" let before = "\n" let after = "\n\n" - elseif newchar == "t" || newchar == "T" || newchar == "<" + elseif newchar ==# "t" || newchar ==# "T" || newchar == "<" let dounmapr = 0 let dounmapb = 0 if !mapcheck("","c") @@ -193,7 +196,7 @@ function! s:wrap(string,char,...) " {{{1 cnoremap > > endif let default = "" - if newchar == "T" + if newchar ==# "T" let default = matchstr(@@,'<\zs.\{-\}\ze>') endif let tag = input("<",default) @@ -209,26 +212,23 @@ function! s:wrap(string,char,...) " {{{1 let before = "<".tag.">" let after = "" endif - elseif newchar == 'l' || newchar == '\' - let dounmapr = 0 - if !mapcheck("","c") - let dounmapr = 1 - cnoremap =closematch() - endif + elseif newchar ==# 'l' || newchar == '\' let env = input('\begin','{') + let env = env . s:closematch(env) echo '\begin'.env - if dounmapr - silent! cunmap - endif if env != "" let before = '\begin'.env let after = '\end'.matchstr(env,'[^}]*').'}' endif - elseif newchar == 'f' + elseif newchar ==# 'f' || newchar ==# 'F' let func = input('function: ') if func != "" let before = substitute(func,'($','','').'(' let after = ')' + if newchar ==# 'F' + let before = before . ' ' + let after = ' ' . after + endif endif elseif idx >= 0 let spc = (idx % 3) == 1 ? " " : "" @@ -288,7 +288,7 @@ function! s:reindent() " {{{1 endfunction " }}}1 function! s:dosurround(...) " {{{1 - let g:scount = v:count1 + let scount = v:count1 let char = (a:0 ? a:1 : s:inputtarget()) let spc = "" if char =~ '^ ' @@ -305,7 +305,7 @@ function! s:dosurround(...) " {{{1 let append = "" let original = @@ let @@ = "" - exe "norm di".char + exe "norm d".(scount==1 ? "": scount)."i".char "exe "norm vi".char."d" let keeper = @@ let okeeper = keeper " for reindent below @@ -315,11 +315,11 @@ function! s:dosurround(...) " {{{1 endif let oldline = getline('.') let oldlnum = line('.') - if char == "p" + if char ==# "p" let append = matchstr(keeper,'\n*\%$') let keeper = substitute(keeper,'\n*\%$','','') let @@ = "" - elseif char == "s" || char == "w" || char == "W" + elseif char ==# "s" || char ==# "w" || char ==# "W" " Do nothing let @@ = "" elseif char =~ "[\"'`]" @@ -337,11 +337,11 @@ function! s:dosurround(...) " {{{1 "let g:rem2 = rem2 "let g:keeper = keeper let regtype = getregtype('"') - if char =~ '[\[({<]' || spc + if char =~# '[\[({]*$') + let tail = matchstr(a:str,'.[^\[\](){}<>]*$') if tail =~ '^\[.\+' return "]" elseif tail =~ '^(.\+' @@ -455,8 +456,8 @@ function! s:closedcmd() return getcmdline() . cm endfunction -nnoremap DSurround :call dosurround(inputtarget()) -nnoremap CSurround :call changesurround() +nnoremap DSurround :call dosurround(inputtarget()) +nnoremap CSurround :call changesurround() nnoremap YSurround :set opfunc=opfuncg@ nnoremap YSSurround :call opfunc(v:count1) vnoremap VSurround :call opfunc(visualmode())