git 将您的 .vim ~/.vimrc 添加到 github(又名点文件)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18197705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:54:07  来源:igfitidea点击:

Adding your .vim ~/.vimrc to github (aka dot files)

gitvimdotfiles

提问by John Tomson

I have seen a few people that have git repos with their dot files. I'm wondering if they just

我见过一些人有 git repos 和他们的 dot 文件。我想知道他们是否只是

cd ~/
git init
git add .vimrc
// etc

? And then that's how they keep it up to date? Or do they probably make copies and sync them?

? 然后这就是他们保持最新的方式?或者他们可能会复制并同步它们?

What strategy do you guys recommend or use? Mostly don't wanna commit and push my entire ~/

你们推荐或使用什么策略?主要是不想提交并推动我的整个〜/

Thanks

谢谢

回答by sitaktif

Making a git repository of your home is probably a bad idea (you would be spending more time creating your .gitignore file than on doing what you really want to do).

为你的家制作一个 git 存储库可能是一个坏主意(你会花更多的时间来创建你的 .gitignore 文件而不是做你真正想做的事情)。

I suggest using a separate git directory for your dotfiles (eg. ~/git/dotfiles) and them making symlinks to your home (eg. ln -s ~/git/dotfiles/.vim ~/.vim, etc.).

我建议为您的 dotfiles(例如~/git/dotfiles)使用单独的 git 目录,并且它们制作指向您家的符号链接(例如ln -s ~/git/dotfiles/.vim ~/.vim,等)。

If you can't be bothered creating symlinks manually each time you want to install your dotfiles somewhere, you can use a script like the following one: https://github.com/gibfahn/dot/blob/master/link.

如果每次想要在某处安装点文件时都不想手动创建符号链接,则可以使用如下脚本:https: //github.com/gibfahn/dot/blob/master/link

回答by romainl

I have my ~/.vimdirectory under version control and my "real" vimrc(the one with all my settings) inside that directory, at ~/.vim/vimrc:

我的~/.vim目录处于版本控制之下,而我的“真实”目录vimrc(包含我所有设置的目录)位于该目录中~/.vim/vimrc

~/
---- .vim/
---- ---- (plugins and stuff)
---- ---- vimrc
---- .vimrc

My regular ~/.vimrchas only one line:

我的常客~/.vimrc只有一行:

runtime vimrc

No need to create symlinks or whatever.

无需创建符号链接或其他任何东西。

This is how I would push my config on a new machine where Git has already been installed:

这就是我将我的配置推送到已经安装了 Git 的新机器上的方式:

$ cd
$ git clone [email protected]:romainl/dotvim.git .vim
$ echo "runtime vimrc" > .vimrc

What follows is the whole creation process. I assume that you have created an account and a repo named "vimconfig" on Github and that you already have a lovingly crafted ~/.vimrcand a well organized ~/.vim/.

下面是整个创作过程。我假设您已经在 Github 上创建了一个帐户和一个名为“vimconfig”的存储库,并且您已经拥有一个精心制作~/.vimrc且组织良好的~/.vim/.

$ cd
$ mv .vimrc .vim/vimrc
$ echo "runtime vimrc" > .vimrc
$ cd .vim
$ git init
$ echo "This is my Vim config." > README
$ git add *
$ git commit -m "My Vim config is versioned."
$ git remote add origin https://github.com/username/vimconfig.git
$ git push origin master

At that point, you should have the same content on Github andin your local repository.

此时,您应该在 Github本地存储库中拥有相同的内容。

You manage that repository normally and push your commits when you are ready. Simple.

您可以正常管理该存储库,并在准备好后推送您的提交。简单的。

Note that the whole Github thing is only useful if you need/want to sync your config on multiple machines or, somehow need/want to share it with others. If you don't, there's no real point using GitHub at all.

请注意,整个 Github 内容仅在您需要/想要在多台机器上同步您的配置,或者以某种方式需要/想要与他人共享时才有用。如果你不这样做,那么使用 GitHub 根本没有任何意义。

(edit)

(编辑)

Vim 7.4 introduced a new, very useful, scheme: it looks for the usual ~/.vimrcand also for ~/.vim/vimrcso that's even less work for you:

Vim 7.4 引入了一个新的、非常有用的方案:它寻找通常的~/.vimrc,也~/.vim/vimrc为你提供更少的工作:

$ cd .vim
$ git init
$ echo "This is my Vim config." > README
$ git add *
$ git commit -m "My Vim config is versioned."
$ git remote add origin https://github.com/username/vimconfig.git
$ git push origin master

Of course, the strategy I suggested initially is still valid if you have to deal with mixed Vim versions: Vim knows what to do and won't crap out in an endless loop.

当然,如果您必须处理混合 Vim 版本,我最初建议的策略仍然有效:Vim 知道该做什么并且不会无限循环。

回答by Idan Arye

I already have a "bundle" folder where I put all my plugins to load via Pathogen. So I made that folder my git folder(with the plugins as submodules) and put my vimrc there.

我已经有一个“捆绑”文件夹,我将所有插件放在其中通过Pathogen加载。所以我将该文件夹设为我的 git 文件夹(插件作为子模块)并将我的 vimrc 放在那里。

In the official .vimrcI write:

在官方.vimrc我写道:

let $MYVIMRC="<path_to_vimrc_in_bundle_folder>"
source $MYVIMRC
...
call pathogen#infect()

and I don'tversion it!

没有版本它!

This allows me to share my configuration between my Linux machine at home and my Windows box at work. I can also put in the official .vimrcconfigurations specific to the machine, or ones I don't want to make available publicly(like the dbextprofiles that contains logins and passwords...)

这允许我在家里的 Linux 机器和工作中的 Windows 机器之间共享我的配置。我还可以放入.vimrc特定于机器的官方配置,或者我不想公开的配置(例如包含登录名和密码的dbext配置文件......)

回答by arctelix

Here is a platform agnostic and shell agnostic solution with no dependancies other then the bourne compatible shell you have available(bash, zsh, ksh, etc). It works on mac, linux, & windows:

这是一个平台不可知和 shell 不可知的解决方案,除了您可用的 bourne 兼容 shell(bash、zsh、ksh 等)之外,没有任何依赖项。它适用于 mac、linux 和 windows:

dotsys

点系统

It will automatically synchronize changes to your dotfiles with github and multiple machines, along with many other features.

它会自动将更改与 github 和多台机器以及许多其他功能同步到您的 dotfiles。

回答by Ian Canino

Check out StreakyCobra's solution in Hacker News:

Hacker News 中查看 StreakyCobra 的解决方案:

git init --bare $HOME/.myconf
alias config='/usr/bin/git --git-dir=$HOME/.myconf/ --work-tree=$HOME'
config config status.showUntrackedFiles no

where ~/.myconfis the location of the bare git repository. Then any files within $HOMEcan be versioned like so:

~/.myconf裸git存储库的位置在哪里。然后$HOME可以像这样对其中的任何文件进行版本控制:

config status
config add .vimrc
config commit -m "Add vimrc"
config add .config/redshift.conf
config commit -m "Add redshift config"
config push

If you need further explanation, Nicola Paolucci provided a great explanation.

如果您需要进一步解释,Nicola Paolucci 提供了很好的解释