简体   繁体   中英

Push local git repo with sub repos (vim)

I'm using Vim and pathogen as a plugin manager, and i have cloned a lot of plugins into my .vim folder. Now i want my custom vim to be easily accessible on multiple systems, so i made my .vim directory a git repo. I added everything with 'git add .' and pushed it to a bitbucket repository. Now whenever i want to clone this repo to another computer it only creates the folders where the plugins should be, but not the files. I guess they were added as submodules automatically, but i can't seem to pull them from there respective sources with a simple command like 'git submodule update' it only says "No submodule mapping found in .gitmodules for path 'bundle/plugin' . What do i need to do to prevent this? Thanks in advance.

Your .vim is your own, so you can just tell it where you got the commits from. Since you already have the clones, easiest is just to do the config directly. The defaults are kept in the .gitmodules file,

git config -f .gitmodules submodule.fugitive.path fugitive
git config -f .gitmodules submodule.fugitive.url https://github.com/tpope/vim-fugitive.git

and so forth. Get comfortable with shell functions to make small production runs handy:

make-github-submodule () {
        git config -f .gitmodules submodule.$1.path $1
        git config -f .gitmodules submodule.$1.url https://github.com/$2.git
}

make-github-submodule fugitive tpope/vim-fugitive
make-github-submodule vundle VundleVim/Vundle.vim

and so forth, that looks handy enough.

Yes, you can store the contents of your .vim as a Git repo using submodules but may I suggest a different approach.

It may be easier to manage all this with a simple script that clones your plugins into the proper place that pathogen expects.

I also go between multiple computers and this approach has served me very well.

Here is what I use (a Perl script):

#!/usr/bin/perl -w   
use strict;

my $dotVimDir;
my $home=$ENV{HOME};
my @repos=qw(
    https://github.com/tpope/vim-fugitive|tpope-fugitive
    https://github.com/tpope/vim-flagship|tpope-flagship
    # etc...
);

sub runCommand($) {
    my ($command)=@_;
    open CMD,"$command |";
    my @output=<CMD>;
    close CMD;
    return @output;
}

MAIN: {
    my $platform=$^O;
    if($platform eq 'linux') {
        $dotVimDir="$home/.vim";
    } elsif($platform eq 'MSWin32') {
        $dotVimDir="$home/vimfiles";
    } else {
        print "unknown platform\n";
        exit 1;
    }

    runCommand("cp -R ./vimplugins/autoload $dotVimDir");
    runCommand("cp -R ./vimplugins/ftplugin $dotVimDir");

    my ($repo,$folderName);
    foreach(@repos) {
        ($repo,$folderName)=split("\Q|",$_,2);

        my $fullPath="$dotVimDir/bundle/$folderName";
        if (-d "$fullPath") {
            runCommand("git -C $fullPath stash -u");
            runCommand("git -C $fullPath pull origin master");
        } else {
            runCommand("git clone $repo $fullPath");
        }
    }

    exit;
}

You can keep this script in a separate repo (perhaps called something like myconfig ). I also keep other spare files in this repo (for example various autoload or ftplugin s) and this script also copies those over.

Here is a ruby script that also accomplishes this goal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM