title: How to put regex match to the end of line in vim?
body: <p>I have some lines. I want to search for a regex in these lines and append the match to the end of matching lines. For example, this is input:</p>
  
  <pre><code>foo x
  </code></pre>
  
  <p>Here is the expected output:</p>
  
  <pre><code>foo x foo
  </code></pre>
  
  <p>I can use a substitute command to achieve this conversion:</p>
  
  <pre><code>%s/\(f\w*\).*/\0 \1/
  </code></pre>
  
  <p>But I think this solution is sometimes too difficult to apply or to adapt to some use cases. I look for a simpler solution using global command similar to that:</p>
  
  <pre><code>g/\f\w*/ s/$/ &lt;??&gt;/
  </code></pre>
  
  <p>I want to filter the lines first. Then use the match in each line in substitute command. Is there a command that lets me use the match in global command in place of <code>&lt;??&gt;</code>?</p>