mirror of
https://github.com/tpope/vim-surround.git
synced 2025-11-15 14:53:49 -05:00
Save, set, and restore startofline
Consider this code:
```javascript
_.map(
(
mapObjOnK
)
);
```
If the cursor is on the 3rd line and you press <kbd>d</kbd><kbd>s</kbd><kbd>b</kbd>, the code will become
```javascript
_.map(
);
mapObjOnK
```
The problem occurs if `startofline` is off.
With this change, I set it before processing the the call to
`dosurround`, and then, after the call, I'm unsetting it if
it was unset.
This commit is contained in:
committed by
Tim Pope
parent
baf89ad264
commit
9857a87463
@@ -367,6 +367,8 @@ function! s:reindent() abort " {{{1
|
|||||||
endfunction " }}}1
|
endfunction " }}}1
|
||||||
|
|
||||||
function! s:dosurround(...) " {{{1
|
function! s:dosurround(...) " {{{1
|
||||||
|
let sol_save = &startofline
|
||||||
|
set startofline
|
||||||
let scount = v:count1
|
let scount = v:count1
|
||||||
let char = (a:0 ? a:1 : s:inputtarget())
|
let char = (a:0 ? a:1 : s:inputtarget())
|
||||||
let spc = ""
|
let spc = ""
|
||||||
@@ -388,6 +390,9 @@ function! s:dosurround(...) " {{{1
|
|||||||
if a:0 > 1
|
if a:0 > 1
|
||||||
let newchar = a:2
|
let newchar = a:2
|
||||||
if newchar == "\<Esc>" || newchar == "\<C-C>" || newchar == ""
|
if newchar == "\<Esc>" || newchar == "\<C-C>" || newchar == ""
|
||||||
|
if !sol_save
|
||||||
|
set nostartofline
|
||||||
|
endif
|
||||||
return s:beep()
|
return s:beep()
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@@ -414,6 +419,9 @@ function! s:dosurround(...) " {{{1
|
|||||||
if keeper == ""
|
if keeper == ""
|
||||||
call setreg('"',original,otype)
|
call setreg('"',original,otype)
|
||||||
let &clipboard = cb_save
|
let &clipboard = cb_save
|
||||||
|
if !sol_save
|
||||||
|
set nostartofline
|
||||||
|
endif
|
||||||
return ""
|
return ""
|
||||||
endif
|
endif
|
||||||
let oldline = getline('.')
|
let oldline = getline('.')
|
||||||
@@ -478,6 +486,9 @@ function! s:dosurround(...) " {{{1
|
|||||||
else
|
else
|
||||||
silent! call repeat#set("\<Plug>C".(a:0 > 2 && a:3 ? "S" : "s")."urround".char.newchar.s:input,scount)
|
silent! call repeat#set("\<Plug>C".(a:0 > 2 && a:3 ? "S" : "s")."urround".char.newchar.s:input,scount)
|
||||||
endif
|
endif
|
||||||
|
if !sol_save
|
||||||
|
set nostartofline
|
||||||
|
endif
|
||||||
endfunction " }}}1
|
endfunction " }}}1
|
||||||
|
|
||||||
function! s:changesurround(...) " {{{1
|
function! s:changesurround(...) " {{{1
|
||||||
|
|||||||
Reference in New Issue
Block a user