Search and replace global modifier
- by mrucci
Is there any reason why non-global/first-occurrence substitution is the default in many text editing programs (vim, sed, perl, etc.)?
I am talking about the /g flag of search and replace commands like:
:s/pan/focaccia/g # in vim
sed 's/sfortuna/fortuna/g' # with sed
that will substitute every occurrence of the search pattern with the replacement string.
After (not too) many years of vim and sed usage I still did not find any use case for non-global substitutions. Is there some valid historical reason? Or it is because it is?
Thanks.