title: How does the vim "write with sudo" trick work?
body: <p>Many of you have probably seen the command that allows you to write on a file that needs root permission, even when you forgot to open vim with sudo:</p>
  
  <pre><code>:w !sudo tee %
  </code></pre>
  
  <p>The thing is that I don't get what is exactly happening here.</p>
  
  <p>I have already figured this:
  <code>w</code> is for this</p>
  
  <pre><code>                                                        *:w_c* *:write_c*
  :[range]w[rite] [++opt] !{cmd}
                          Execute {cmd} with [range] lines as standard input
                          (note the space in front of the '!').  {cmd} is
                          executed like with ":!{cmd}", any '!' is replaced with
                          the previous command |:!|.
  </code></pre>
  
  <p>so it passes all the lines as standard input.</p>
  
  <p>The <code>!sudo tee</code> part calls <code>tee</code> with administrator privileges.</p>
  
  <p>For all to make sense, the <code>%</code> should output the filename (as a parameter for <code>tee</code>), but I can't find references on the help for this behavior.</p>
  
  <p><strong>tl;dr</strong> Could someone help me dissect this command?</p>