Ftplugins aren't loaded when you switch between buffers. They are loaded only when you open a buffer for the first time, or if you change it's filetype. It's easy to check. Add some
:echomsg in your ftplugins, and play with buffers. As a rule, by default ftplugins are loaded only once per buffer: when the buffer is opened/created -- or when we execute
:e (foo.ft) from
foo.ft buffer, otherwise
:edit won't trigger filetype autocommands when editing a buffer already opened.
EDIT: I stand corrected, thanks @Mass. What I describe regarding the behaviour of
:e is a consequence of
set hidden in my .vimrc. Switching buffers by switching windows doesn't seems to be impacted by
'hidden', I observe it doesn't trigger any filetype autocommand.
As you define global stuff in your filetype plugin, well, it gets redefined every time the ftplugin gets loaded. If you open a java ftplugin where
<Leader>cc is mapped to execute
javac, you'd loose you mapping for compiling C.
The fix is easy: never define global things in ftplugins. Define only local things. The mappings shall be buffer local, as well as the commands.
Also, your mappings won't take advantage of one of the earlier feature of vim (compared to vi): the quickfix feature. Unless you make program is improperly configured (like the one shipped with mingw), you just need
:make %< to compile mono-file projects. It'll works with C++, C, fortran...