Skip to content

Commit

Permalink
Take into account 'gdefault' setting
Browse files Browse the repository at this point in the history
If the user has 'gdefault' set (not the default), then the "g" flag
actually turns *off* global replacement instead of turning it on. So,
check for 'gdefault' in order to decide whether or not to pass the "g"
(we always want to do global replacements).

Reported here:

  https://twitter.com/briemens/status/1080554857998757888

My guess at problem here:

  https://twitter.com/wincent/status/1080616775681798144

Confirmed that it was here:

  https://twitter.com/briemens/status/1080618527218978816
  • Loading branch information
wincent committed Jan 3, 2019
1 parent ee755ab commit c00f46b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions autoload/scalpel.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function! scalpel#cword(curpos) abort
return join(l:word, '')
endfunction

function s:g()
return &gdefault ? '' : 'g'
endfunction

function! scalpel#substitute(patterns, line1, line2, count) abort
if a:count == -1
" No range supplied, operate on whole buffer.
Expand All @@ -42,6 +46,8 @@ function! scalpel#substitute(patterns, line1, line2, count) abort
let l:currentline=l:firstline
endif

let l:g=s:g()

" As per `:h E146`, can use any single-byte non-alphanumeric character as
" delimiter except for backslash, quote, and vertical bar.
if match(a:patterns, '\v^([^"\\|A-Za-z0-9 ]).*\1.*\1$') != 0
Expand All @@ -57,7 +63,7 @@ function! scalpel#substitute(patterns, line1, line2, count) abort
let l:report=&report
try
set report=10000
execute l:currentline . ',' . l:lastline . 's' . a:patterns . 'gce#'
execute l:currentline . ',' . l:lastline . 's' . a:patterns . l:g . 'ce#'
catch /^Vim:Interrupt$/
execute 'set report=' . l:report
return
Expand All @@ -80,7 +86,7 @@ function! scalpel#substitute(patterns, line1, line2, count) abort
" Avoid unwanted "Backwards range given, OK to swap (y/n)?" messages.
if l:currentline > l:firstline
" Drop c flag.
execute l:firstline . ',' . l:currentline . '-&gce'
execute l:firstline . ',' . l:currentline . l:g . '-&ce'
endif
return
endif
Expand All @@ -89,7 +95,7 @@ function! scalpel#substitute(patterns, line1, line2, count) abort
" Loop around to top of range/file and continue.
" Avoid unwanted "Backwards range given, OK to swap (y/n)?" messages.
if l:currentline > l:firstline
execute l:firstline . ',' . l:currentline . '-&gce'
execute l:firstline . ',' . l:currentline . l:g . '-&ce'
execute 'set report=' . l:report
endif
endfunction

0 comments on commit c00f46b

Please sign in to comment.