Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 1 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

 
discard

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.