Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using VIM (MacVim to be specific) I've been trying to add a number of shortcuts to my .vimrc file that have different syntax in different languages.

I'm using autocmd to add different keymappings depending on the filetype, but the javascript and perl filetypes .js and .pl don't get the mappings.

My attempt to have a / comment out a visually selected block (and ? to uncomment it):

autocmd FileType php,js,java,cpp    vnoremap <buffer> / :s/^/\/\/ /<cr>gv
autocmd FileType php,js,java,cpp    vnoremap <buffer> ? :s/^\s*\/\/ \?//<cr>gv
autocmd FileType sql                vnoremap <buffer> / :s/^/-- /<cr>gv
autocmd FileType sql                vnoremap <buffer> ? :s/^--\s\?//<cr>gv  
autocmd FileType pl                 vnoremap <buffer> / :s/^/## /<cr>gv
autocmd FileType pl                 vnoremap <buffer> ? :s/^\s*##\s\?//<cr>gv

This works for the php, java, cpp and sql files, but not for pl and js files.

share|improve this question
up vote 2 down vote accepted

Vim's name for a file type is not necessarily the same as the extension. The file type name for javascript is javascript and the file type name for perl is perl. In your autocommands, change js to javascript and pl to perl. You can find Vim's mappings from extensions to file types in $VIMRUNTIME/filetype.vim.

share|improve this answer
Thank you garyjohn, that did for job. – davur Sep 12 '10 at 4:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.