title: Detect filetype in vim without valid file extension
body: <p>I'm looking for a way to determine the filetype of a file in vim and set the syntax highlighting based on the filetype. The only catch is I cannot use the file extension for determining the filetype.</p>
  
  <p>This is my scenario: I use <code>vimdiff</code> or <code>gvimdiff</code> as my <code>P4DIFF</code> tool, which shows the changes between the files in my local copy and the ones from the perforce server. Perforce seems to bring in the files from the perforce server into the /tmp directory and uses the <code>PID</code> to name the file, for example:</p>
  
  <pre><code>/tmp/tmp.24673.23
  </code></pre>
  
  <p>This was for a C++ source file.</p>
  
  <p>The most frequent filetypes I encounter in the perforce repository are C/C++ sources and header files, Makefiles, python scripts, perl scripts, ruby scripts, and tcl scripts.</p>
  
  <ul>
  <li><p>I've looked into using <code>modeline</code>, but most of the sources in our tree do not have this information embedded in the file.</p></li>
  <li><p><a href="https://stackoverflow.com/a/10584645/380757">This</a> post mentions about a possible approach to search and identify a magic pattern. I could not find any consistent magic pattern that I could get a high success rate with.</p></li>
  <li><p>Tried using the <code>file</code> binary on my linux box to see what results I get. It seems to identify C/C++ sources well, but fails for Makefiles and even python scripts (which don't have the hashbang)</p></li>
  </ul>
  
  <p>One good thing is that, among the 2 files that are compared, the file on the right is from my local copy and hence has the correct file name with extension, thereby syntax highlighting is enabled correctly for the file on the right.</p>
  
  <p>Is there a way I could leverage this to set the same syntax highlighting for the file displayed on the left ?</p>
  
  <p>Any alternate solutions to this problem are also welcome.</p>