title: What does the "g" stand for in Ruby's "gsub" and in Vim's substitution command?
body: <p>Both Ruby and Vim use "g" with substitution commands to mean "all occurrences." <strong>What does the "g" stand for?</strong></p>
  
  <p>Specifically, in Ruby, the <a href="http://ruby-doc.org/core/classes/String.html" rel="noreferrer">String class</a> has two "sub" commands: <code>sub</code> will replace only the first occurrence, and <code>gsub</code> will replace all occurrences. For example:</p>
  
  <pre><code>string = "One potato, two potato, three potato, four."
  string.sub('potato','banana') # =&gt; "One banana, two potato, three potato, four."
  string.gsub('potato','banana') # =&gt; "One banana, two banana, three banana, four."
  </code></pre>
  
  <p>Similarly, in Vim, <code>:%s/foo/bar</code> will look through the whole file (which is what <code>%</code> means) and substitute one occurrence per line, but <code>:%s/foo/bar/g</code> will do all occurrences on each line.</p>
  
  <p>My guess would be that in both cases, "g" means "greedy," because both the Ruby commands and the Vim command accept a regular expression, but my understanding of greedy matching is "match the longest possible substring meeting these criteria," not "match as many substrings as possible." (See "<a href="http://www.regular-expressions.info/repeat.html" rel="noreferrer">Watch Out for The Greediness!</a>")</p>