title: Autocommand not working in Vim, how to set makeprg based upon the filetype?
body: <p>I use Vim editor for programming and here's the problem that I am facing.</p>
  
  <p>I am using multiple tabs to edit C++ and Python files simultaneously and I have added the following in my .vimrc file</p>
  
  <pre><code>filetype plugin indent on
  au filetype python set mp=python3\ %
  au filetype cpp set mp=g++\ -Werror\ -Wextra\ -Wall\ -ansi\ -pedantic-errors\ -g\ %
  </code></pre>
  
  <p>i.e all I want is that when I switch to a tab with a Python file and run <code>:make</code>, it should run <code>:!python3 %</code>, and when I switch to a tab with a C++ file and run <code>:make</code> it should run <code>:!g++ -Werror -Wextra -Wall -ansi -pedantic-errors -g %</code></p>
  
  <p>However it's not working, and everytime I switch the tab and run <code>:make</code>, it tries to execute <code>!g++ -Werror -Wextra -Wall -ansi -pedantic-errors -g %</code> and when I run <code>:set ft?</code> on the 2 files(i.e Python and C++) to check whether the filetypes have been correctly identified or not, I get the correct result i.e python and cpp.</p>
  
  <p>Then why is this autocommand not working? Am I missing something?
  Thanks for your patience</p>