title: Read the contents of a modified buffer in Vim
body: <p>How can I access the contents of a modified buffer in Vim?</p>
  
  <p>For example, if I want to concatenate the contents to a temporary file, like:</p>
  
  <pre><code>:! cat % &gt; /tmp/modified.txt
  </code></pre>
  
  <p>But that gives me the last saved contents of the file (rightly so?). I do want to avoid saving the file before because this interaction is <em>meant</em> to allow some analysis without saving the buffer first.</p>
  
  <p>It seems that the Python extension for Vim allows you to do something like:</p>
  
  <pre><code>def buffer_contents(buffer=vim.current.buffer):
      contents = buffer[:]
  </code></pre>
  
  <p>But I can't find any <code>VimL</code> references for the same functionality.</p>
  
  <p>EDIT: It seems I could do something like:</p>
  
  <pre><code>:let buffer_contents = join(getline(1, '$'), '$')
  </code></pre>
  
  <p>At this point I just wonder if there is a builtin approach.</p>