Skip to content

Commit

Permalink
Handle repeated 'g' flags passed to :Acks
Browse files Browse the repository at this point in the history
This is amazingly edge casey, but the 'g' flag can be repeated, toggling
the effect each time. So:

  :Acks /foo/bar/gggg

Would actually have the effect of turning off global replacement. As
bf9bffb said:

    The docs for `:Acks` promise that:

    > Takes all of the files currently in the |quickfix| listing and
    > performs a substitution of all instances of {pattern} (a standard
    > Vim search |pattern|) by {replacement}.

So in order to be true to the promise of replacing "all instances" we
need to make sure that there is only a single 'g' flag.
  • Loading branch information
wincent committed Jan 4, 2019
1 parent be3f9d7 commit d9998e0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions autoload/ferret/private.vim
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,14 @@ function! ferret#private#acks(command) abort
if l:options !~# 'e'
let l:options.='e'
endif
if !&gdefault && l:options !~# 'g'
let l:options.='g'
if !&gdefault
if l:options !~# 'g'
let l:options.='g'
else
" Make sure there is exactly one 'g' flag present, otherwise an even
" number of 'g' flags will actually cancel each other out.
let l:options=substitute(l:options, 'g', '', 'g') . 'g'
endif
elseif &gdefault && l:options =~# 'g'
" 'gdefault' inverts the meaning of the 'g' flag, so we must strip it.
let l:options=substitute(l:options, 'g', '', 'g')
Expand Down

0 comments on commit d9998e0

Please sign in to comment.