Vim inoremap for specific filetypes

后端 未结 5 2128
孤独总比滥情好
孤独总比滥情好 2020-11-29 11:38

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.

5条回答
  •  臣服心动
    2020-11-29 12:09

    You need to do 2 things:

    • create a mapping local to a specific buffer by using the option for inoremap.
    • load the mappings for just a specific filetype.

    This can be done via an autocommand in your .vimrc like so:

    autocmd FileType php inoremap  ( ()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  ( ()i
    inoremap  { {}ko
    inoremap  i
    

    I personally lean more towards the ftplugin approach but having a everything in your .vimrc file can be nice.

提交回复
热议问题