So I was editing my ~/.vimrc file from the home directory and saved it, but when I went to check whether it had been updated in the vimrc file (for git) which is located at /.vim/vimrc, it did not show any update that I made in ~/.vimrc. I've been researching but still can't find anything helpful yet. I'm still very new to Git and GitHub so please be patient with me.

I had some troubles setting ~/.vim a git repository as when I committed, it saved everything but I only want ~/.vimrc in there. All the things that I have in ~/.vim (as of right now) are:
1. autoload (contains pathogen.vim)
2. bundle (contains vim-live-latex-preview)
3. colors (contains all the colorschemes)
4. doc (contains some info about the live-latex-preview)
5. VIMRC (contains the vimrc file)

  • 1
    Welcome to Vi and Vim! I don't understand... If your Git repository is checked out under ~/.vim, then your ~/.vimrc will be outside of it... Why did you expect it to make it into Git if it's outside? Note that you don't need to use a ~/.vimrc (at least with Vim version 8 or later), Vim will also accept a ~/.vim/vimrc file as its main configuration file. So maybe just get rid of ~/.vimrc and use ~/.vim/vimrc exclusively?
    – filbranden
    Commented May 27, 2020 at 4:04
  • So I tried out something like this. I added a mapping command A to my ~/.vimrc and added a mapping command B to my ~/.vim/VIMRC/vimrc. When I opened up a file and edited something, only A works. Also, the reason I have a folder named VIMRC contains vimrc (and I git init inside that folder) is that I have other things like ColorSchemes and Plugins in ~/.vim. And when I tried to commit in ~/.vim, it saved everything in that directory. I don't know if that helps with anything and I have to say that this is my very first day learning about git & github so please be understanding! Thanks :D Commented May 27, 2020 at 4:31
  • ~/.vim/VIMRC/vimrc will most definitely *not* work. I have ~/.vim` in a git repository but I have a ~/.vim/.gitignore that includes /plugged so that ~/.vim/plugged (where vim-plug fetches plug-ins) won't be pushed to vim. Also, ~/.vim/vimrc only works if ~/.vimrc doesn't exist...
    – filbranden
    Commented May 27, 2020 at 4:36
  • An alternative would be to make ~/.vimrc a symbolic link to the vimrc file inside your git repository... But I still think storing your ~/.vim in a git repository and managing the exceptions with a .gitignore is best. That way you can fully set up Vim with a single git clone command. (Well, that and plug-in initialization if you're using vim-plug or similar...)
    – filbranden
    Commented May 27, 2020 at 4:37
  • 1
    @filbranden and if you don’t have time, I’m happy to as well :)
    – D. Ben Knoble
    Commented May 27, 2020 at 12:27

1 Answer 1


Required background

Vim's runtimepath and directories

The runtimepath (:help 'runtimepath') is a list of directories searched for runtime files, such as documentation under doc, colorschemes under colors, and more.

The runtimepath virtually always includes ~/.vim (for user settings), the vim runtime (shipped with vim), and ~/.vim/after (for overriding or extending anything that came before). You will probably also find $VIM/vimfiles or similar; this is used (I think) by programs that wish to install some of their own vim files when they are installed (e.g., I think clisp came with some extra syntax files).

Plugins, packages, and package managers may manipulate the runtimepath; consult the relevant documentation for information.

I find :put =split(&rtp, ',') a handy shortcut to produce a list of my runtimepath.

Vim's user customization (:help startup and :help vimrc)

At step number 3 of the startup process, vim will read a vimrc file. It can be located in several places, depending on your operating system. Most of them allow you to use ~/.vimrc or ~/.vim/vimrc, which is relevant for our discussion. The first one found is used, in the order given.

So to use only ~/.vim/vimrc, it must be the first file in the list of vimrc locations under :help vimrc!

You can often check what vimrc was detected with the command :edit $MYVIMRC inside vim.

Here's another relevant bit of documentation:

RECOMMENDATION: Put all your Vim configuration stuff in the $HOME/.vim/ directory ($HOME/vimfiles/ for MS-Windows). That makes it easy to copy it to another system.

-- :help vimrc

More details are at :help .vimrc.


So, I can't and won't give an overview of git here. It's too big. But I'll link you to some resources:

  • a workshop I gave to get people up-and-running with git (and not lie to them about the underlying model): git-wizard
  • a list of resources I collected for the workshop: resources.md
  • in particular, the git book

One thing I will say about git's model is that by default, the directory containing .git/ is the "top" or "root" of a git-tracked repository. Also by default, git will not track any file you don't git add to the repository first (so new files are initially "untracked"). As far as I know, it is very difficult (perhaps impossible) to track files that are above the root of the repository.

So, if you have

|- .git/ ...
|- autoload/ ...

It will be very hard (if not impossible) to track ~/.vimrc in the same repo. Luckily, you can track ~/.vim/vimrc

Lastly, git has a concept of "ignoring" certain files (like compiled binaries or tags produced by :helptags). But you tell it what to ignore using files like .gitignore and the one named by core.excludesFile. See both git help ignore and git help config.

In this situation…

Well, it really depends on what you want to do. As I've tried to explain, both vim and git give you the power; they don't do much without you asking, but you've got to learn their core models and their defaults well enough to understand what to ask them to do.

In this case, I would suggest

  1. Move ~/.vimrc to ~/.vim/vimrc, and don't even try to do ~/.vim/VIMRC/vimrc.
  2. If you don't want to commit everything in a repository, don't git add .—that's how you tell git to track everything in a repository.
  3. If you want to ignore some things in git, learn how gitignore works (see the reference I gave above).
  4. If you want git to track a file, git add file and git commit are the best ways to tell git to care about a file for the rest of its life. (Of course, you still have to git add and git commit when you've made changes later, but now those changes will show up in git status and git diff, because the files are "tracked".)
  5. If you want to "start over" to try to set things up with git the right way the first time around, you can remove the .git directory. But I would make a backup copy of your entire ~/.vim somewhere, just in case things go awry. You can also make a second backup without the .git directory to try practicing git before you go and setup your ~/.vim directory for real. (This is much simpler than trying to use git rebase and git filter-branch to clean up a mess, particularly when the repo is small, personal, and has a short history. In a bigger setting, such as a large open-source project or a corporate project, such a thing would be Very Bad™. You would want to learn how to use rebase and filter-branch on only your local commits for that situation. Once commits are pushed/public, it is best to leave them untouched. You can always create a new branch to try to clean them up. :endrant)
  • 1
    Annnnd writing that gave me a sense of "this question is too broad"...
    – D. Ben Knoble
    Commented May 27, 2020 at 18:25
  • 1
    After reading your answer, I can certainly see why you said that. Anyhow, it's a very eye-opening and thorough answer. It seems like I will have a lot of stuffs to learn there, and I will definitely report back how things go afterwards. I really appreciate your help! Commented May 27, 2020 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.