1

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.

1 Answer 1

4

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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .