This is an extension on work in: https://vi.stackexchange.com/a/8130/26305
Uses replace to handle existing comments not in specific indentation, instead of vim key commands and allows a dictionary of filetypes which can be easily toggled with 'set filetype=X'
Paste the following, declare your missing filetype in dictionary (default comment char is '#') and use Ctrl-m to toggle comment on one or multiple lines.
let commentTextMap = {
\'c': '\/\/',
\'h': '\/\/',
\'cpp': '\/\/',
\'java': '\/\/',
\'php': '\/\/',
\'javascript': '\/\/',
\'groovy': '\/\/',
\'python': '#',
\'sh': '#',
\'vim': '"',
\'make': '#',
\'conf': '#',
\}
noremap <silent> <expr> <C-m> ((synIDattr(synID(line("."), col("."), 0), "name") =~ 'comment\c') ?
\ ':<S-Right>:s/^\([ \t]*\)' . get(commentTextMap, &filetype, '#') . '/\1/<CR>:nohl<CR>'<CR>' :
\ ':<S-Right>:s/^/' . get(commentTextMap, &filetype, '#') . '/<CR>:nohl<CR>'
\ ) . ':nohl<CR>:call histdel("/", -1)<CR>'