Alex Rivera | Logout

Vim inoremap for specific filetypes

Asked 2012-01-11T18:56:46.953
12

I've added some simple inoremap commands to my .vimrc to help with parens and brackets completion, but I only want them to apply to php files.

 inoremap ( ()<Esc>i
 inoremap { {<CR>}<Esc>ko
 inoremap <? <?php ?><Esc><Left>i

How to I set these commands to be active only when I'm editing a .php file?

Edit
Report

2 Answers

12

Use autocmd FileType:

autocmd FileType php,c,java inoremap ( ()<Esc>i
answered 2012-01-11T19:19:33.433
2

There may be a better way to do it, but this should work:

autocmd FileType php call Inoremaps()
fu! Inoremaps()
   inoremap ...
endfu
answered 2012-01-11T19:20:09.860

Your Answer