From d9998e0dcb4b5569c46af00d42cc46634da26c91 Mon Sep 17 00:00:00 2001 From: Greg Hurrell Date: Fri, 4 Jan 2019 10:03:02 +0100 Subject: [PATCH] Handle repeated 'g' flags passed to :Acks 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 bf9bffbc21ad3 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. --- autoload/ferret/private.vim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/autoload/ferret/private.vim b/autoload/ferret/private.vim index 65c3739..95bac09 100644 --- a/autoload/ferret/private.vim +++ b/autoload/ferret/private.vim @@ -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')