0

To perform a buffer-wide substitution on all occurrences of foo (and not just the 1st one in a line), we can do

%s/foo/bar/g

The g flag may be omitted by setting this in the vimrc as

set gdefault

If the pattern foo is not found, vim raises an error

E486: Pattern not found: foo

This error can be avoided by specifying the e flag to the substitution operator i.e.

%s/foo/bar/ge

My question is, can an equivalent option (say edefault) that can be put together in a vimrc to achieve this effect?

  • 3
    No, there is not and btw: I would not recommend setting gdefault. It is to obscure and I suspect too many plugins cannot handle it – Christian Brabandt Jun 20 at 12:52
  • @ChristianBrabandt Ok, I agree with your views on gdefault. What about edefault. Can something be cooked up? – Krishna Jun 20 at 19:05
  • I am not sure what you mean with cooked up. In interactive mode, a missing edefault does not make sense since the error message is quite helpful. Scripts/plugins however can use various ways to compensate, using either try/catch or always including the e flag. So what exact problem are you trying to solve here? – Christian Brabandt Jun 21 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.