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

后端 未结 12 1319
花落未央
花落未央 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:29

    You can use stow for switching configuration (any dotfiles, not only .vimrc)

    Install stow:

    $ apt install stow
    

    Create multiple directories for each configurations:

    ~$ ls -d ~/dotfiles/vim*
    vim-all vim-webdev vim-go
    

    Put different .vimrc's in them:

    $ find ~/dotfiles -name .vimrc
    /home/username/vim-golang/.vimrc
    /home/username/vim-webdev/.vimrc
    /home/username/vim-all/.vimrc
    

    Now you can instantinate vim-golang config with this command (should be run inside dotfiles directory):

    ~$ cd ~/dotfiles
    
    dotfiles$ stow -v vim-golang
    LINK: .vimrc => dotfiles/vim-golang/.vimrc
    

    Now it's linked:

    $ cd ~ && ls -l .vimrc 
    .vimrc -> dotfiles/vim-golang/.vimrc
    

    If you need to switch config, just re-stow it:

    ~$ cd dotfiles
    
    dotfiles$ stow -v -D vim-golang
    UNLINK: .vimrc
    
    dotfiles$ stow -v vim-webdev
    LINK: .vimrc => dotfiles/vim-webdev/.vimrc
    
    $ cd ~ && ls -l .vimrc 
    .vimrc -> dotfiles/vim-webdev/.vimrc
    

    More reading of it here: Managing dotfiles with GNU stow

    Pros: pretty simple, no vim plugin dependencies, can be used for managing all dotfiles, not only .vimrc.

    Cons: configs are independent of each other, you need to manage/update each of them separately (if you dont switch/update you configs too often - it'll not be the issue).

提交回复
热议问题