Change the mapping of F5 on the basis of specific file type

Viewed 3203

The current mapping of my F5 key is:

imap <F5> <esc>:w\|!python %<CR>

Now I want that if I'm editing any python file (it will be better if it also recognizes file other than standard .py format like .pyd etc) then this mapping works as it is. But, if I edit a Java file it is mapped to something like:

imap <F5> <esc>:w\|!javac %<CR>

And when I'm editing any .c or .cpp file then F5 is mapped to this:

imap <F5> <esc>:w\|!make %<CR>

I have no idea how to proceed.

2 Answers
Related