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.
Use autocmd FileType
:
autocmd FileType php,c,java inoremap ( ()<Esc>i
put them in a this file
~/.vim/ftplugin/php.vim
There may be a better way to do it, but this should work:
autocmd FileType php call Inoremaps()
fu! Inoremaps()
inoremap ...
endfu
You need to do 2 things:
<buffer>
option for inoremap
.This can be done via an autocommand in your .vimrc
like so:
autocmd FileType php inoremap <buffer> ( ()<Esc>i
The other way option is by creating a filetype plugin. (see :h ftplugin
for more details)
A simple example is do create a file named, ~/.vim/after/ftplugin/php.vim
and place your mappings inside like so:
inoremap <buffer> ( ()<Esc>i
inoremap <buffer> { {<CR>}<Esc>ko
inoremap <buffer> <? <?php ?><Esc><Left>i
I personally lean more towards the ftplugin approach but having a everything in your .vimrc
file can be nice.
Add them to the ftplugin file in the after directory:
~/.vim/after/ftplugin/php.vim
More info in this answer.
Edit: This file, and maybe even the directory, will not be there by default. You may have to make it if you don't see it there.