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.

link|improve this question
feedback

1 Answer

up vote 0 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.

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

Your Answer

 
or
required, but never shown

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