Skip to content

Commit

Permalink
Fix edgecase where ds would move the inner text
Browse files Browse the repository at this point in the history
  • Loading branch information
tpope committed Jan 25, 2008
1 parent dff4740 commit bb456dd
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions plugin/surround.vim
Expand Up @@ -424,8 +424,9 @@ function! s:dosurround(...) " {{{1
exe 'norm '.strcount.'[/d'.strcount.']/'
else
exe 'norm d'.strcount.'i'.char
" One character backwards
call search('.','bW')
endif
"exe "norm vi".char."d"
let keeper = getreg('"')
let okeeper = keeper " for reindent below
if keeper == ""
Expand All @@ -436,8 +437,6 @@ function! s:dosurround(...) " {{{1
let oldline = getline('.')
let oldlnum = line('.')
if char ==# "p"
"let append = matchstr(keeper,'\n*\%$')
"let keeper = substitute(keeper,'\n*\%$','','')
call setreg('"','','V')
elseif char ==# "s" || char ==# "w" || char ==# "W"
" Do nothing
Expand All @@ -450,32 +449,23 @@ function! s:dosurround(...) " {{{1
call setreg('"','/**/',"c")
let keeper = substitute(substitute(keeper,'^/\*\s\=','',''),'\s\=\*$','','')
else
exe "norm! da".char
exe "norm da".char
endif
let removed = getreg('"')
let rem2 = substitute(removed,'\n.*','','')
let oldhead = strpart(oldline,0,strlen(oldline)-strlen(rem2))
let oldtail = strpart(oldline, strlen(oldline)-strlen(rem2))
let regtype = getregtype('"')
if char == 'p'
let regtype = "V"
endif
if char =~# '[\[({<T]' || spc
let keeper = substitute(keeper,'^\s\+','','')
let keeper = substitute(keeper,'\s\+$','','')
endif
if col("']") == col("$") && col('.') + 1 == col('$')
"let keeper = substitute(keeper,'^\n\s*','','')
"let keeper = substitute(keeper,'\n\s*$','','')
if oldhead =~# '^\s*$' && a:0 < 2
"let keeper = substitute(keeper,oldhead.'\%$','','')
let keeper = substitute(keeper,'\%^\n'.oldhead.'\(\s*.\{-\}\)\n\s*\%$','\1','')
endif
let pcmd = "p"
else
if oldhead == "" && a:0 < 2
"let keeper = substitute(keeper,'\%^\n\(.*\)\n\%$','\1','')
endif
let pcmd = "P"
endif
if line('.') < oldlnum && regtype ==# "V"
Expand All @@ -488,7 +478,6 @@ function! s:dosurround(...) " {{{1
silent exe 'norm! ""'.pcmd.'`['
if removed =~ '\n' || okeeper =~ '\n' || getreg('"') =~ '\n'
call s:reindent()
else
endif
if getline('.') =~ '^\s\+$' && keeper =~ '^\s*\n'
silent norm! cc
Expand Down

0 comments on commit bb456dd

Please sign in to comment.