title: vim regex replace multiple consecutive spaces with only one space
body: <p>I often work with text files which have a variable amount of whitespaces as word separators (text processors like Word do this, to distribute fairly the whitespace amount due to different sizes of letters in certain fonts and they put this annoying variable amount of spaces even when saving as plain text).</p>
  
  <p>I would like to automate the process of replacing these sequences of whitespaces that have variable length with single spaces. I suspect a regex could do it, but there are also whitespaces at the beginning of paragraphs (usually four of them, but not always), which I would want to let unchanged, so basically my regex should also not touch the leading whitespaces and this adds to the complexity.</p>
  
  <p>I'm using vim, so a regex in the vim regex dialect would be very useful to me, if this is doable.</p>
  
  <p>My current progress looks like this:</p>
  
  <pre><code>:%s/ \+/ /g
  </code></pre>
  
  <p>but it doesn't work correctly.</p>
  
  <p>I'm also considering to write a vim script that could parse text lines one by one, process each line char by char and skip the whitespaces after the first one, but I have a feeling this would be overkill.</p>