title: Detecting file type for C++ standard headers with vim
body: <p>Standard headers for C++ are typically installed in /usr/include/c++/4.x (in Linux). Since most of the headers do not have any extension (.h, .hpp, etc.), vim cannot recognize the format for these files as C++.</p>
  
  <p>I have seen this other <a href="https://stackoverflow.com/questions/10584580/can-i-make-vim-do-syntax-highlighting-on-c-headers-that-dont-have-extensions">question</a> in SO, but the solutions posted in there do not solve my problem. One solution there involves using <code>modeline</code> but standard C++ headers do not include a vim-friendly signature. Instead, they include in the first line something like:</p>
  
  <pre><code>// &lt;algorithm&gt; -*- C++ -*-
  </code></pre>
  
  <p>I guess I could search for that pattern (<code>-*- C++ -*-</code>) in order to detect the file type. The other solution posted in the previously mentioned SO question actually goes in that direction. The answer suggests to use:</p>
  
  <pre><code>au BufRead * if search('MagicPattern', 'nw') | setlocal ft=cpp | endif
  </code></pre>
  
  <p>so I have tried to do:</p>
  
  <pre><code>au BufRead * if search('-*- C++ -*-', 'nw') | setlocal ft=cpp | endif
  </code></pre>
  
  <p>but it does not work (i.e., the file type is not detected).</p>
  
  <p>Is it possible to detect the file type using that approach? Does it exist any plugin or any other way to solve this?</p>