This stuff is defined in your
bash_completion script. Sometimes you can find that in
/etc and sometimes in
Mine has this line:
_install_xspec '*.@([ao]|so|so.!(conf|*/*)|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)' vi vim gvim rvim view rview rgvim rgview gview emacs xemacs sxemacs kate kwrite
It does exactly what you want.
I imagine your installation is too old. You can try updating "bash-completion", or editing that file yourself.
Alternatively, you could have your
.bashrc edit the
_xspecs variable manually -- bash-completion does not provide an interface to do this for you.
Edit: it turns out the OP was not using the bash-completion package at all (so just using the built-in "dumb" filename completion). In that case installing it and following the setup instructions is sufficient. On Linux this package is typically installed by default, and no user setup is required.