Changing Vim behavior by file type using single `.vimrc` (without ftplugin)

后端 未结 2 1607
名媛妹妹
名媛妹妹 2021-01-06 15:04

How to change Vim behaviour using single .vimrc file (without ftplugin) in elegant way ?

What do I mean is ... if I run many commends for C/C++ file , e

2条回答
  •  被撕碎了的回忆
    2021-01-06 15:32

    I'd probably do per-filetype functions to do the setup for me. Shamelessly ripping off @Derek...

    function! SetUpLispBuffer()
        set lisp
        set showmatch
        set cpoptions-=m
        set autoindent
    endfunction
    
    function! SetUpCBuffer()
        set formatprg=c:\\AStyle\\bin\\AStyle.exe\ -A4Sm0pHUk3s4
        set tw=80
    endfunction
    
    if has("autocmd")
        augroup LISP
            au!
            au BufReadPost *.cl call SetUpLispBuffer()
        augroup END
        augroup C
            au!
            autocmd BufNewFile,BufRead *.{cpp,c,h} call SetUpCBuffer
        augroup END
    endif
    

    A lot less to change when you want to make changes and much less cut&paste too.

提交回复
热议问题