Remove whitespace in some cases
This commit is contained in:
parent
736d1b5482
commit
d99a4b9e01
@ -282,13 +282,19 @@ function! s:insert(...) " {{{1
|
|||||||
endfunction " }}}1
|
endfunction " }}}1
|
||||||
|
|
||||||
function! s:reindent() " {{{1
|
function! s:reindent() " {{{1
|
||||||
if @@ =~ '\n' && (exists("b:surround_indent") || exists("g:surround_indent"))
|
if (exists("b:surround_indent") || exists("g:surround_indent"))
|
||||||
silent norm! '[=']
|
silent norm! '[=']
|
||||||
endif
|
endif
|
||||||
endfunction " }}}1
|
endfunction " }}}1
|
||||||
|
|
||||||
function! s:dosurround(...) " {{{1
|
function! s:dosurround(...) " {{{1
|
||||||
|
let g:scount = v:count1
|
||||||
let char = (a:0 ? a:1 : s:inputtarget())
|
let char = (a:0 ? a:1 : s:inputtarget())
|
||||||
|
let spc = ""
|
||||||
|
if char =~ '^ '
|
||||||
|
let char = strpart(char,1)
|
||||||
|
let spc = 1
|
||||||
|
endif
|
||||||
let newchar = ""
|
let newchar = ""
|
||||||
if a:0 > 1
|
if a:0 > 1
|
||||||
let newchar = a:2
|
let newchar = a:2
|
||||||
@ -302,6 +308,7 @@ function! s:dosurround(...) " {{{1
|
|||||||
exe "norm di".char
|
exe "norm di".char
|
||||||
"exe "norm vi".char."d"
|
"exe "norm vi".char."d"
|
||||||
let keeper = @@
|
let keeper = @@
|
||||||
|
let okeeper = keeper " for reindent below
|
||||||
if @@ == ""
|
if @@ == ""
|
||||||
let @@ = original
|
let @@ = original
|
||||||
return ""
|
return ""
|
||||||
@ -330,6 +337,10 @@ function! s:dosurround(...) " {{{1
|
|||||||
"let g:rem2 = rem2
|
"let g:rem2 = rem2
|
||||||
"let g:keeper = keeper
|
"let g:keeper = keeper
|
||||||
let regtype = getregtype('"')
|
let regtype = getregtype('"')
|
||||||
|
if char =~ '[\[({<]' || spc
|
||||||
|
let keeper = substitute(keeper,'^\s\+','','')
|
||||||
|
let keeper = substitute(keeper,'\s\+$','','')
|
||||||
|
endif
|
||||||
if oldtail == rem2 && col('.') + 1 == col('$')
|
if oldtail == rem2 && col('.') + 1 == col('$')
|
||||||
if oldhead =~# '^\s*$' && a:0 < 2
|
if oldhead =~# '^\s*$' && a:0 < 2
|
||||||
"let keeper = substitute(keeper,'\n\s*','\n','')
|
"let keeper = substitute(keeper,'\n\s*','\n','')
|
||||||
@ -362,7 +373,9 @@ function! s:dosurround(...) " {{{1
|
|||||||
let @@ = substitute(keeper,'\n\s+\n','\n\n','g')
|
let @@ = substitute(keeper,'\n\s+\n','\n\n','g')
|
||||||
call setreg('"','','a'.regtype)
|
call setreg('"','','a'.regtype)
|
||||||
silent exe "norm! ".(a:0 < 2 ? "" : "").pcmd.'`['
|
silent exe "norm! ".(a:0 < 2 ? "" : "").pcmd.'`['
|
||||||
call s:reindent()
|
if removed =~ '\n' || okeeper =~ '\n'
|
||||||
|
call s:reindent()
|
||||||
|
endif
|
||||||
if getline('.') =~ '^\s\+$' && keeper =~ '^\s*\n'
|
if getline('.') =~ '^\s\+$' && keeper =~ '^\s*\n'
|
||||||
silent norm! cc
|
silent norm! cc
|
||||||
endif
|
endif
|
||||||
|
Loading…
Reference in New Issue
Block a user