How to switch between multiple vim configurations with a command or local vimrc files?

后端 未结 12 1341
花落未央
花落未央 2020-12-04 05:43

I work in several groups, each of which has its own tab/indentation/spacing standards in C.

Is there a way to have separate selectable VIM configurations for each so

12条回答
  •  鱼传尺愫
    2020-12-04 06:08

    I have this in $HOME/.vimrc:

    if filereadable(".vim.custom")
        so .vim.custom
    endif
    

    This allows me to put a .vim.custom file in every directory to load commands and options specific to that directory. If you're working on multiple projects that have deep directory structures you might need something more sophisticated (e.g. walk up the directory tree until a .vim.custom is found), but the same basic idea will work.

    UPDATE:

    I now do something like this in order to read a .vim file from the same directory as the file I'm editing, regardless of what the current directory is.

    let b:thisdir=expand("%:p:h")
    let b:vim=b:thisdir."/.vim"
    if (filereadable(b:vim))
        execute "source ".b:vim
    endif
    

提交回复
热议问题